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
my ($account,$record) = @_;
### construct the command line, using:
# -r = remove the account's home directory for us
my @cmd = ($userdelex, "-r", $account);
print "Deleting account...";
my $result = 0xffff & system @cmd;
# the return code is 0 for success, non-0 for failure, so we inver
return "$userdelex failed";
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.