用户建立脚本
1执行user_create.sh userlist passlist
2建立userlist
**列表中的用户 **
3设定userlist
列表中的密码为passlist列表中的密码
4当脚本后面跟的文件个数不足两个时,报错。
5当文件行数不一致时报错
6当文件不存在时报错
7当用户存在时报错
#!/bin/bash
[ "$#" -lt "2" ]&&{
echo error:please input userfile and passfile
exit
}
[ "$USER" != "root" ]&&{
echo error:you are not super user
exit
}
[ -e "$1" ]||{
echo $1 is not exist
exit
}&&{
[ -e "$2" ]||{
echo $2 is not exist
exit
}
}
a=$(cat $1 | wc -l )
b=$(cat $2 | wc -l )
[ "$a" != "$b" ] &&{
echo $1 $2 行数不一致
exit
}
USER=(`cat $1`)
AUTH=(`cat $2`)
MAX=$[${#USER[@]}-1]
for num in `seq 0 $MAX`
do
id ${USER[$num]} &>/dev/null &&{
userdel -r ${USER[$num]}
echo error:${USER[$num]} is exist
}||{
useradd ${USER[$num]}&&{
echo ${AUTH[$num]} | passwd --stdin ${USER[$num]} &>/dev/null
echo ${USER[$num]} is created
}
}
done