企业实践题4:
批量创建10个系统帐号oldboy01-oldboy10并设置密码(密码为随机8位字符串)。
我的脚本1=======================
[root@master day7]# cat shell_0301.sh #!/bin/bash . /etc/init.d/functions [ $UID -ne 0 ] &&{ echo "only allow root to exec this cmd." exit } for n in `seq -w 10` do pass="`echo $RANDOM|md5sum|cut -c 1-8`" useradd oldboy$n &>/dev/null && echo $pass|passwd --stdin oldboy$n &>/dev/null if [ $? -eq 0 ];then action "useradd oldboy$n" /bin/true else action "useradd oldboy$n" /bin/false fi echo -e "oldboy$n-t$pass" >> /oldboy.user.txt
done
我的脚本2=======================
[root@master day7]# cat shell_0302.sh #!/bin/bash echo stu{01..10}|tr " " " "|sed -r 's#(.*)#useradd 1;pass=$RANDOM|md5sum|cut -c 1-8;echo "$pass|passwd --stdin 1;echo -e "1 `echo "$pass"`">> /tmp/oldboy.log"#g'|bash