shell编程

题目:

批量创建n个用户帐号test01-testn并设置密码(密码为随机8位字符串),最后将创建用户名和密码输出到/usr/user.txt中。

 

 

 

#!/bin/bash
#shell编程-批量添加用户
#批量创建n个用户帐号
read -p "please input a number(adduser): " n
for i in `seq -w $n`
do
#test01-testn并设置密码
   useradd test$i
#密码为随机8位字符串
if [ $n -ge 0 -a $n -lt 10 ]
        then
                passwd=`echo $RANDOM |md5sum |cut -c 1-8`
                echo "test0$i $passwd" >> /tmp/user2.txt
else
        passwd=`echo $RANDOM |md5sum |cut -c 1-8`
        echo "test$i $passwd" >> /tmp/user2.txt
   echo $passwd |passwd -stdin test$i
echo "Victory!"
fi
done

 

posted @ 2022-05-27 09:38  飞鱼Dai  阅读(46)  评论(0)    收藏  举报