批量创建10个系统帐号zkg01-zkg10并设置密码(密码为随机8位字符串)
脚本如下:

#!/bin/sh
#批量创建用户名和密码
#by zkg 2019-08-22
. /etc/init.d/functions

if [ $UID -ne 0 ];then
echo "create user need root privage"
exit
fi

for user in echo zkg{01..10}
do
check_user=grep "\b$user\b" /etc/passwd|wc -l
if [ $check_user -ne 0 ];then
action "this $user is exist,no create user" /bin/false
continue
fi

    PASSWD=`echo $RANDOM|md5sum|cut -c 1-8`
    useradd $user && \
    echo "$PASSWD"|passwd --stdin $user
    RETVAL=$?
    if [ $RETVAL -eq 0 ];then
            action "$user is created successfully"  /bin/true
    else
            action "PASSWD is failed" /bin/false
    fi
    echo "$user:$PASSWD" >>/opt/shell/passwd.txt

done