批量创建用户和删除用户
批量创建10个系统账号(gota01-gota10),并设置密码(密码为随机数,要求是字符和数字的混合) ###不用for循环的实现思路可参见https://user.qzone.qq.com/49000448/blog/1422183723 #!/bin/ bash . /etc/init.d/ functions user = " gota " passfile = " /tmp/user.log " for num in ` seq - w 10 ` #从1至10 - w等位补全,宽度相等,不足的前面补0 do pass = " `echo " test$RANDOM " |md5sum|cut -c 3-11` " #RANDOM的随机数范围:0~32767 useradd $user$num &> /dev/ null && echo -e " $user${num}:$pass " >> $passfile if [ $? -eq 0 ]; then action " $user$num is ok " /bin/ true else action " $user$num is fail " /bin/ false fi done chpasswd < $passfile #给多个用户设置密码的命令 密码文件格式: 用户名1:口令1 cat $passfile 批量删除