#!/bin/env bash #产生1000个以139开头的电话号码并保存文件phonenum.txt file=/root/phonenum.txt for ((i=1;i<=1000;i++)) do n1=$[$RANDOM%10] n2=$[$RANDOM%10] n3=$[$RANDOM%10] n4=$[$RANDOM%10] n5=$[$RANDOM%10] n6=$[$RANDOM%10] n7=$[$RANDOM%10] n8=$[$RANDOM%10] echo"139$n1$n2$n3$n4$n5$n6$n7$n8" >> $file done
#!/bin/bash # random phonenum # 循环1000次产生电话号码并保存到文件 for i in {1..1000} do n1=$[RANDOM%10] n2=$[RANDOM%10] n3=$[RANDOM%10] n4=$[RANDOM%10] n5=$[RANDOM%10] n6=$[RANDOM%10] n7=$[RANDOM%10] n8=$[RANDOM%10] echo"139$n1$n2$n3$n4$n5$n6$n7$n8" >> phonenum.txt done
#!/bin/bash i=1 while [ $i -le1000 ] do n1=$[$RANDOM%10] n2=$[$RANDOM%10] n3=$[$RANDOM%10] n4=$[$RANDOM%10] n5=$[$RANDOM%10] n6=$[$RANDOM%10] n7=$[$RANDOM%10] n8=$[$RANDOM%10] echo"139$n1$n2$n3$n4$n5$n6$n7$n8" >> phonenum.txt let i++ done
#!/bin/bash for i in {1..1000} do n1=$[$RANDOM%10] n2=$[$RANDOM%10] n3=$[$RANDOM%10] n4=$[$RANDOM%10] n5=$[$RANDOM%10] n6=$[$RANDOM%10] n7=$[$RANDOM%10] n8=$[$RANDOM%10] echo"139$n1$n2$n3$n4$n5$n6$n7$n8" >> phonenum.txt done
#!/bin/bash #create phone num file for ((i=1;i<=1000;i++)) do n1=$[$RANDOM%10] n2=$[$RANDOM%10] n3=$[$RANDOM%10] n4=$[$RANDOM%10] n5=$[$RANDOM%10] n6=$[$RANDOM%10] n7=$[$RANDOM%10] n8=$[$RANDOM%10] echo"139$n1$n2$n3$n4$n5$n6$n7$n8" |tee-a phonenum.txt done
#!/bin/bash count=0 while true do n1=$[$RANDOM%10] n2=$[$RANDOM%10] n3=$[$RANDOM%10] n4=$[$RANDOM%10] n5=$[$RANDOM%10] n6=$[$RANDOM%10] n7=$[$RANDOM%10] n8=$[$RANDOM%10] echo"139$n1$n2$n3$n4$n5$n6$n7$n8" |tee-a phonenum.txt && let count++ if [ $count -eq1000 ];then break fi done
或者 for i in `cat user_pass.file` do user=`echo $i|cut -d: -f1` pass=`echo $i|cut -d: -f2` useradd $user echo$pass|passwd --stdin$user done
#!/bin/bash #crate user and set passwd #产生一个保存用户名和密码的文件 echo user0{1..3}:itcast$[$RANDOM%9000+1000]#@~|tr ' ' '\n'|tr ':' ' ' >> user_pass.file #循环创建5个用户 while read user pass do useradd $user echo$pass|passwd --stdin$user done < user_pass.file