Hey all,
crud:x:503:503::/home/tunnel:/bin/bash
test:x:504:45:Test Account:/home/test:/bin/false
test4:x:506:45:test Account:/home/test4:/bin/false
test2:x:507:45:Test Account:/home/test2:/bin/false
daniel:x:508:45:Crudles:/home/daniel:/bin/false
The followowing hash is created below with the following code...
%users = (
'crud' => '503',
'test' => '45',
'test4' => '45',
'test2' => '45',
'daniel'=> '45'
);
#!/usr/bin/perl -w
use Data::Dumper;
$file = '/etc/passwd';
$user = "test4";
open PASSWD, "$file" or die "Cannot open $file for reading :$!";
#Store /etc/passwd as a file
while ($lines = <PASSWD>) {
@lines = split (/:/, $lines);
#Store all users and their gids in a hash!
$users{$lines[0]} = $lines[3];
}
close PASSWD;
print Data::Dumper->Dump( [\%users], ['*users'] );
#Check to see if #user exists
if ( ! defined $users{$user} ) {
print "Sorry user $user does not exist! \n";
}elsif (! defined $users{$user}{'45'} ) {
print "Sorry the user $user does not have a GID of 45! \n";
} else {
print "Found $user! This user has a GID of 45! \n";
}
For some reason it will check the first if statement (! defined
$users{$user}) and check this OK. But when I get to the second if
statement ( ! defined $users{$user}{'45'} ) it will never return true no
matter what $user is set to? I figured that ! defined
$users{$user}{'45'} would return false if for example $user = crud, but
if $user = test4 then it should return to the last else statement?
Any ideas,
Dan
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]