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