cannot match string

2005-05-11 Thread Jonathan Soons

I am trying to lock out a batch of users. They are all in file cleanup.txt.
All the users exist in /etc/shadow. I have made a backup of /etc/shadow to 
play with.
I cannot figure out why I cannot match users from the file with usernames in 
field 0 
of /etc/shadow.bak. I am writing to newshadow to be on the safe side.
If the line:

if ($fields[0] eq $user)

were ever true the script would be fine.
Can anyone see what I am doing wrong?
 
#!/opt/csw/bin/perl
open(SHADOW,  /etc/shadow.bak);
@shadows = SHADOW;
open(NAMES,  cleanup.txt);
@users = NAMES;
close(NAMES);
close(SHADOW);
open(NEWSHADOW,  newshadow); 
LINE: foreach $line (@shadows)
{
@fields = split /:/, $line;
foreach $user (@users)
{
if ($fields[0] eq $user)  #this is never true???
{
$fields[1] = '*LK*';
$joined = join(:, @fields);
print NEWSHADOW $joined;
next LINE;
}
}
$joined = join(:, @fields);
print NEWSHADOW $joined;
}
close(NEWSHADOW);


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




RE: cannot match string

2005-05-11 Thread Wagner, David --- Senior Programmer Analyst --- WGO
Jonathan Soons wrote:
 I am trying to lock out a batch of users. They are all in file
 cleanup.txt. 
 All the users exist in /etc/shadow. I have made a backup of
 /etc/shadow to play with. I cannot figure out why I cannot match
 users from the file with usernames in field 0 
 of /etc/shadow.bak. I am writing to newshadow to be on the safe
 side. 
 If the line:
 
 if ($fields[0] eq $user)
 
 were ever true the script would be fine.
 Can anyone see what I am doing wrong?
 
Since you are reading in all the names at once and never doing a chomp 
on the users, you are more than likely having a carriage return as part of 
user. So $fields[0] will not equal $user.

You might want to create a hash by user and then use the fields[0] as 
the key into the hash. Now you get the data on one action verese going through 
the array each time.   if ( exists $HashOfLockedOutUsers{$fields[0]} ) then you 
can do your *LK* othterwise std write.

As a secondary note, if you replace your file9s) with some sample data 
as part of __DATA__, now I can run your script. As it is, I don't see what you 
have and have to guess.  You could do something like:

script
__DATA__
data for shadow
endofdatashadow
datafornames
endofdatafornames

you replace your open and @shadows with a read until endofdatashadow 
and you replace open and @user with a read until endof datanames.

Now I can work your data and assist in real time.

Just a thought.

Wags ;)


 #!/opt/csw/bin/perl
 open(SHADOW,  /etc/shadow.bak);
 @shadows = SHADOW;
 open(NAMES,  cleanup.txt);
 @users = NAMES;
 close(NAMES);
 close(SHADOW);
 open(NEWSHADOW,  newshadow);
 LINE: foreach $line (@shadows)
   {
   @fields = split /:/, $line;
   foreach $user (@users)
   {
   if ($fields[0] eq $user)  #this is never true???
   {
   $fields[1] = '*LK*';
   $joined = join(:, @fields);
   print NEWSHADOW $joined;
   next LINE;
   }
   }
   $joined = join(:, @fields);
   print NEWSHADOW $joined;
   }
 close(NEWSHADOW);



***
This message contains information that is confidential
and proprietary to FedEx Freight or its affiliates.
It is intended only for the recipient named and for
the express purpose(s) described therein.
Any other use is prohibited.
***


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: cannot match string

2005-05-11 Thread Jeff Eggen
 Jonathan Soons [EMAIL PROTECTED] 11/05/2005 12:45:23 pm 

I am trying to lock out a batch of users. They are all in file
cleanup.txt.
All the users exist in /etc/shadow. I have made a backup of
/etc/shadow to play with.
I cannot figure out why I cannot match users from the file with
usernames in field 0 
of /etc/shadow.bak. I am writing to newshadow to be on the safe
side.
If the line:

I think this is more suited to a shell command then editing the shadow
file directly, since bad things can happen if you trash your shadow
file.  Try this:

for userid in `cat cleanup.txt`
do
echo locking user $userid
passwd -l $userid
done

This should work.  The passwd -l $userid will lock the account for
you.

Jeff Eggen
IT Programmer Analyst
Saskatchewan Government Insurance
Ph (306) 751-1795
email [EMAIL PROTECTED]
DISCLAIMER*
This e-mail and any files transmitted with it are confidential and intended 
solely for the use of the individual or entity to whom they are addressed.  If 
you are not the named addressee, please notify the sender immediately by e-mail 
if you have received this e-mail by mistake and delete this e-mail from your 
system. If you are not the intended recipient you are notified that using, 
disclosing, copying or distributing the contents of this information is 
strictly prohibited.
DISCLAIMER*

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response