创建用户的脚本

来源:互联网 发布:光纤网络布线认识 编辑:程序博客网 时间:2024/05/21 19:17
#!/bin/bash
if [ ! -f /mnt/userfile ]; then
    echo "the userfile not exist"
    exit 0
fi
if [ ! -f /mnt/passfile ]; then
    echo "the passfile not exist"
    exit 0
fi

MAXUSERLINE=$(cat /mnt/userfile |wc -l)
MAXPASSLINE=$(cat /mnt/passfile |wc -l)
if [ "$MAXUSERLINE" != "$MAXPASSLINE" ]; then

    echo "the two file is not equal"
    exit 0
fi

for NUM in $(seq 1 $MAXUSERLINE)
do
    USER=` sed -n ${NUM}p /mnt/userfile`
    PASS=` sed -n ${NUM}p /mnt/passfile`
    useradd $USER &>/dev/null
    if [ "$?" != "0" ]; then
    echo "the user is exist"
    else
    echo $PASS | passwd --stdin $USER
    fi
done
0 0
原创粉丝点击