学习了鸟哥的私房菜,看到帐号的批处理,就试了一遍,以下是部分代码
#!/bash/bin#建立一批账号#2018/8/13export PATH=/bin:/usr/bin:/sbin:/usr/sbinaccountfile="user.passwd"#账号信息的输入read -p "账号开头代码为 " username_startread -p "账号年级为 " username_degreeread -p "账号数字位数为 " nu_nu... -f "$accountfile" ] && mv $accountfile "$accountfile"$(date +%Y%m%d)nu_end=$(($nustart+$nu_amount-1))for((i=$nu_start ; i<=$nu_end ; i++))do nu_len=${#i} #获取i的位数 if [ $nu_nu -lt $nu_len ];then echo "数字位数大于所规定的位数,程序将退出!" exit 1 fi nu_diff=$(($nu_nu-$nu_len)) if [ "$nu_diff" != "0" ];then nu_nn=0000000000 nu_nn=${nu_nn:1:$nu_diff} #代表从nu_nu字符串中第1位开始取出$nu_diff个字符 fi account=${username_start}${username_degree}${nu_nn}${i} if [ "$pwm" == "1" ];then passwd=$account else passwd=$(openssl rand -base64 6) fi echo "$account":"$passwd" | tee -a "$accountfile"donecat "$accountfile" | cut -d ":" -f 1 | xargs -n 1 useradd -mchpasswd < "$accountfile"pwconvecho "OK"