-
Notifications
You must be signed in to change notification settings - Fork 47
/
createaccount
executable file
·74 lines (71 loc) · 2.56 KB
/
createaccount
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/bin/bash
#
# 这支程序主要在帮您创建大量的账号之用,更多的使用方法请参考:
# http://vbird.dic.ksu.edu.tw/linux_basic/0410accountmanager.php#manual_amount
#
# 本程序为鸟哥自行开发,在 CentOS 5.x 上使用没有问题,
# 但不保证绝不会发生错误!使用时,请自行负担风险~
#
# History:
# 2005/09/05 VBird 刚刚才写完,使用看看先~
# 2009/03/04 VBird 加入一些语�??的修改与说明,修改口令产生方式 (用 openssl)
export LANG=zh_CN.UTF-8
export PATH=/sbin:/usr/sbin:/bin:/usr/bin
accountfile="user.passwd"
# 1. 进行账号相关的输入先!
echo ""
echo "例如我们昆山四鎶????学号为: 4960c001 到 4960c060 ,那么:"
echo "账号开头代码涓?? :4"
echo "账号层级或年级为 :960c"
echo "号码鏁????位数为(001~060):3"
echo "账号开始号码为 :1"
echo "账号数量为 :60"
echo ""
read -p "账号开头代码 ( Input title name, ex> std )======> " username_start
read -p "账�??层级或年级 ( Input degree, ex> 1 or enter )=> " username_degree
read -p "号码部分的数字位数 ( Input \# of digital )======> " nu_nu
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
# 判断数字系统
testing0=$(echo $nu_nu | grep '[^0-9]' )
testing1=$(echo $nu_amount | grep '[^0-9]' )
testing2=$(echo $nu_start | grep '[^0-9]' )
if [ "$testing0" != "" -o "$testing1" != "" -o "$testing2" != "" ]; then
echo "输入的号码不�??啦!有非为数字的内容!" ; exit 1
fi
if [ "$pwm" != "1" ]; then
pwm="2"
fi
# 2. 开始输出账号与口令文件!
[ -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
nu_len=${#i}
if [ $nu_nu -lt $nu_len ]; then
echo "数值的位数($i->$nu_len)已经比你�??置的位数($nu_nu)还大!"
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}
fi
account=${username_start}${username_degree}${nu_nn}${i}
if [ "$pwm" == "1" ]; then
password="$account"
else
password=$(openssl rand -base64 6)
fi
echo "$account":"$password" | tee -a "$accountfile"
done
# 3. 开始创建账号与口令!
cat "$accountfile" | cut -d':' -f1 | xargs -n 1 useradd -m
chpasswd < "$accountfile"
pwconv
echo "OK!创建完成!"