1 #!/bin/bash 2 #By spinestars 3 #2013-8-16 4 #cksum5位数获取方法,可能有重复 5 #pd="user`head -200 /dev/urandom | cksum | head -c 5`" 6 7 #php获取5位随即数字 8 pd_num_php(){ 9 /bin/php -q << EOF 10 <?php 11 $pd = mt_rand(10000,99999); 12 echo $pd; 13 ?> 14 EOF 15 } 16 17 #user函数判定用户是否存在,不存在就创建账户 18 user(){ 19 awk 'BEGIN{FS=":"}{print $1}' /etc/passwd | grep $1 20 case $? in 21 0) 22 echo "$1 已经存在" 23 ;; 24 1) 25 useradd $1; 26 echo "$2" | passwd $usern --stdin; 27 echo "$1 $2" >> $3 28 ;; 29 esac 30 } 31 #正文 32 read -p "输入所需账号个数" num 33 read -p "输入账号信息存放文件的路径" user_path 34 for (( n=1;n<=$num;n++ )) 35 do 36 #这里用php函数获取 37 resoult=`pd_num_php` 38 pd="user$resoult" 39 usern=user$n 40 user $usern $pd $user_path 41 done 42 cat $user_path