Re: Adding users from a list or database?
On Fri, Dec 18, 1998 at 05:59:53PM -0600, Steve Phillips wrote:
> What do you do if you have to add many users on a regular basis?
there's a million ways of doing it...i usually write a little script
to do it as i need it. try something like the following, which i wrote
earlier tonight for someone else who asked the same question on another
list...it makes use of useradd and chpasswd, see their man pages for
details.
---cut here---make-users.pl---cut here---
#! /usr/bin/perl
# create users automatically. expects input to be of the form:
#
# login:password:real name
#
# can read input from stdin or by specifying the input file on
# the command line.
# change the following if required to suit your system. they are correct
# for debian and probably for RH and most other linux distributions.
$useradd='/usr/sbin/useradd' ;
$chpasswd='/usr/sbin/chpasswd' ;
# uncomment only one of the following or set to tcsh or csh if you are
# into perversions.
#$shell='/bin/false' ;
$shell='/bin/bash' ;
$|=1;
open(SHELL,"|/bin/bash") || die "couldn't open pipe to bash shell" ;
while (<>) {
chomp ;
($login, $passwd, $realname) = split /:/ ;
print SHELL "$useradd -s '$shell' -m $login\n" ;
$users{$login} = $passwd ;
} ;
print SHELL "\n\n\n$chpasswd <<__EOF__\n" ;
foreach (keys %users) {
print SHELL "$_:$users{$_}\n" ;
}
print SHELL "__EOF__\n" ;
close(SHELL) ;
---cut here---make-users.pl---cut here---
craig
--
craig sanders
Reply to: