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.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|