LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 881|回复: 0

一个可以输入大量账号的 shell !

[复制链接]
发表于 2005-11-20 16:25:49 | 显示全部楼层 |阅读模式
#!/bin/bash
                                                                                                                                               
#这支程式主要在帮你建立大量的帐号
#更多的使用方法请参考:
#http://linux.vbird.org/linux_bas ... r.php#manual_amount
#
#本程式为鸟哥自行开发,在F4上使用没有问题
#但不保证经不会发生错误!使用时,请自行负担风险.
#
#History
#2005/09/05 VBird 刚刚才写完.使用看看先.
PATH=/sbin:/usr/sbin:/bin:/usr/bin;export PATH
accountfile="user.passwd"
                                                                                                                                               
# 进行帐号相关的输入.
read -p "账号开头代码(Input title name, ex> std )=====>" username_start
read -p "账号班级或年级(Input degree, ex> 1 or enter )=>" username_degree
read -p "起始号码(Input start number, ex> 520 )=====>" nu_start
read -p "账号数量(Input amount of users, ex> 100 )====>" nu_amount
read -p "密码标准1)与帐号相同 2)乱数自订 ===========>" pwm
if [ "$username_start" == "" ]; then
   echo "没有输入开头代码,不给执行!" ; exit 1
fi
testing1=`echo $nu_amount | grep '[^0-9]' `
testing2=`echo $nu_start  | grep '[^0-9]' `
if [ "$testing1" != "" ] || [ "$testing2" != "" ]; then
   echo "输入的号码不对喔! 有非为数字的内容!";exit 1
fi
if [ "$pwm" != "1" ]; then
    pwm="2"
fi
# 开始输出帐号与密码档案
[ -f "$accountfile" ] && mv $accountfile "$accountfile"`date +%Y%m%d`
nu_end=$(($nu_start+$nu_amount -1))
for (( i=$nu_start; i<=$nu_end; i++ ))
#[ -f "$accountfile" ] && mv $accountfile "$accountfile"`date +%Y%m%d`
    #  nu_end=$(($nu_start+$nu_amount-1))
     # for (( i=$nu_start; i<=$nu_end; i++ ))
                                                                                                                                               
do
   account=$username_start$username_degree$i
   if [ "$pwm" == "1" ]; then
   password="$account"
   else
       password=""
       test_nu=0
       until [ "$test_nu" == "8" ]
       do
         temp_nu=$((RANDOM*50/32767+30))
         until [ "$temp_nu" != "60" ]
        do
            temp_nu=$(($RANDOM*50/32767+30))
          done
           test_nu=$(($test_nu+1))
           temp_ch=`printf "\x$temp_nu"`
           password=$password$temp_ch
        done
                                                                                                                                               
        fi
        echo "$account":"$password" | tee -a "$accountfile"
done
                                                                                                                                               
#开始建立账号与密码!
   cat "$accountfile" | cut -d':' -f1 |xargs -n 1 useradd -m
   chpasswd < "$accountfile"
   pwconv
   echo "OK 建立完成!"



   详细网址:
http://linux.vbird.org/linux_basic/0340bashshell-scripts.php
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表