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.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.