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>


Reply via email to