in reply to use getpwent to find users and delete them
The documentation (perldoc -f getpwent) indicates that getpwent returns a list of values like:
my ( $name, $passwd, $uid, $gid, $qutoa, $comment, $gcos, $dir, $shell +, $expire ) = getpwent;
and, if the user doesn't exist, it returns a "single meaningless true value". So I'd suggest calling getpwent, and then checking one of the values after the first one to see if it's defined or not. If not, the user ought not exist. So something like:
my ( $name, $passwd, $uid, $gid, $qutoa, $comment, $gcos, $dir, $shell +, $expire ) = getpwent($account); # An account *must* have a UID, so let's check that if ( defined $uid ) { print "User $account uid=$uid. OK to delete user!\n"; } else { print "User $account does not exist...\n"; }
...roboticus
When your only tool is a hammer, all problems look like your thumb.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: use getpwent to find users and delete them
by garcimo (Novice) on May 18, 2018 at 13:48 UTC | |
by Corion (Patriarch) on May 18, 2018 at 13:56 UTC | |
by roboticus (Chancellor) on May 18, 2018 at 14:55 UTC |
In Section
Seekers of Perl Wisdom