[NTLUG:Discuss] Script to create accounts on RH 6.0 (fwd)
A.L.Lambert
alambert at tcjc.cc.tx.us
Fri Mar 31 04:02:08 CST 2000
> Hi all, After spending six hours trying to fix an exchange server
> (microsucks), I'm giving up and I'm wondering if is any script where I
> can have user name and password to create accounts in RH 6.0?
>
> Thanks.
I feel your pain! However, converting to something better is
quite easy (assuming users are using POP3 or IMAP mail). Assuming you can
get it all in a file with a format something like "username,password"
(with one per line), then the following shell script will/should do the
trick. (cut and paste from #!/bin/sh to the last ### line into a file,
edit as appropo, and chmod +x it).
#!/bin/bash
# pass input file to STDIN of the while read line ; do loop
cat /path/inputfile |
while read line ; do
# clear the variables (not needed, but good coding practice)
username=""
password=""
# set the variables
username=`echo $line | cut -d"," -f1`
password=`echo $line | cut -d"," -f2`
# check variables
if [ "$username" != "" -a "$password" != "" ] ; then
# No null variables, create that sucker
useradd $username
# set the password for the new user automagically
echo $username:$password | chpasswd
else
# oops, no username and/or password - maybe blank line in file?
echo "$username:$password" >> /tmp/importerror.log
fi
done
### Copyright A.L.Lambert - Redistribution prohibited
### EOF
If you have a different format of file, you can change the
delimiter character (the -d"," part) to whatever you need (ie: -d" " to
use [SPACE] as a delimiter, or -d":" to use :'s.), or do other tricks with
sed or awk that will separate the file out if the formating is really
bizare (random number of spaces between usernames, more than one
username/pass per line etc.)
That's how to do it with the default RedHat+sendmail setup. Now,
for the advice you didn't ask for :)
What I would HIGHLY recommend, is you don't use a sendmail/system
account setup RH does by default. Sendmail is a royal pain (and notorious
for it's recuring security problems), and using system accounts for simple
things like mail/pop3/imap/ftp/etc. logins is (IMHO) a very "Bad Thing"
(tm). Unless users need to login for shell access, there should never be
a need to use system ID's for users EVER. You should
download/compile/install qmail, vpopmail, and any functionality patches
you find useful to go with the above packages. Vpopmail comes with a
"vadduser" program that will add users password and all with a single
pass, which you would use to replace the "useradd/chpasswd" portion of the
above code. (Or pay/con/beg someone else to do said if all that sounds
like more than you want to get into yourself). Qmail is a wonderful
thing. :)
I'd also recommend upgrading to the latest redhat revision (6.2
just came out) (or at least rpm -Uvh all the updates you can find), or
downgrading to 5.2: The few boxes I've played with 6.0 on seemed to
indicate some system library bugs (or so I assume, since I kept finding
random core files hither and yon on my HD's for no apparent reason, and on
three different occasions my login shell coredumped on me while doing
trivial things like "ls" and "cp") and a general "lack of polish" I found
to be quite distasteful.
Anyhoo, that's my 2 cents. Peace and tranquility to you and
yours.
--
A.L.Lambert
--------------------------------------------------------------------------
If what they've been doing hasn't solved the problem, tell them to do
something else.
-- Gerald Weinberg, "The Secrets of Consulting"
--------------------------------------------------------------------------
More information about the Discuss
mailing list