Bash sciprt question, how to do this????
This is my script
DATE=`/bin/date`
NEW_USERS="/script/userlist"
HOME_BASE="/home/"
cat ${NEW_USERS} | \
while read USER PASSWORD GROUP FULLNAME
do
if [ -z "`grep ^${GROUP}: /etc/group`" ];then
groupadd ${GROUP}
echo "Group ${GROUP} successfully added."
fi
if [ -z "`grep ^${USER}: /etc/passwd`" ]
then
useradd -g ${GROUP} -p ${PASSWORD} -c ${FULLNAME} -m -d ${HOME_BASE}${USER} ${USER}
echo "User ${USER} successfully added."
else
echo "The user has existed"
fi
everything is working fine, now the format of userlist is
USER PASSWORD GROUP FULLNAME
john01 mypass business JOHN
So if I just want to username has no more than 6 characters, password must be over 8 characters, Group just can be "business" or "operation" or "marketing", otherwise the user information is invalid and can't be allowed to add in linux system, and shows "user invaild"information. but now even I input username like john23323e2323403222332, it still be added, so how should I do! Please!
Last edited by yulitao; 03-23-2004 at 08:30 PM.
|