http://qs321.pair.com?node_id=1214762

garcimo has asked for the wisdom of the Perl Monks concerning the following question:

I am looking to clean up some server old users in a environment that unfortunately does not use ldap yet. I have a list of users that i need to check in the servers and if they exist remove them. I was trying to test with this code:
$userdelex = "sudo /usr/sbin/userdel"; # location of userdel executab +le sub DeleteUnixAccount{ my ($account,$record) = @_; ### construct the command line, using: # -r = remove the account's home directory for us my @cmd = ($userdelex, "-r", $account); print "@cmd\n"; print "Deleting account..."; my $result = 0xffff & system @cmd; # the return code is 0 for success, non-0 for failure, so we inver +t if (!$result){ print "succeeded.\n"; return ""; } else { print "failed.\n"; return "$userdelex failed"; } } DeleteUnixAccount(toto);
I was thinking of user user:pwent or getpwent() in order to search if the user is present on the server. I will be connecting to the server in ssh using Net::OpenSSH::Parallel any idea how to use getpwent or user:pwent to do this? thanks in advance.