1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
#!/usr/bin/perl
use Linux::usermod;
use Getopt::Std;
use File::Basename;
getopt('u:n:p:s:h:c:k:a:d:A:D:');
$proname = basename($0);
if(!opt_a or !$opt_d or !$opt_b){
die &usage unless $opt_u && $opt_p ||
$opt_L ||
$opt_U ||
$opt_c ||
$opt_h ||
$opt_s ||
$opt_n ||
$opt_a ||
$opt_d ||
$opt_b ||
$opt_A ||
$opt_D
}
Linux::usermod->add($opt_a) and exit if $opt_a;
Linux::usermod->del($opt_d) and exit if $opt_d;
Linux::usermod->grpadd($opt_A) and exit if $opt_A;
Linux::usermod->grpdel($opt_D) and exit if $opt_D;
$user = Linux::usermod->new($opt_u);
die "No such user\n" unless defined $user->get(uid);
$user->set(password, $opt_p) if $opt_p;
$user->set(comment, $opt_c) if $opt_c;
$user->set(home, $opt_h) if $opt_h;
$user->set(shell, $opt_s) if $opt_s;
$user->set(name, $opt_n) if $opt_n;
$user->tobsd() if $opt_b;
$user->lock if $opt_L;
$user->unlock if $opt_U;
sub usage{
print <<SQ;
$proname:
-n name
-a add
-d delete
-b to bsd style
-h home
-s shell
-c comment
-p new_password
-U unlock
-L lock
-u username
-A groupname
-D groupname
SQ
exit 0
}
|