批量添加用户:
新加一个shell脚本进行批量添加:
<span style="font-size:14px;">#!/bin/bash
#
# 这支程序主要在帮您建立大量的账号之用,
# 更多的使用方法请参考:
# http://linux.vbird.org/linux_basic/0410accountmanager.php#manual_amount
#
# 本程序为鸟哥自行开发,在 FC4 上使用没有问题,
# 但不保证绝不会发生错误!使用时,请自行负担风险~
#
# History:
# 2005/09/05 VBird 刚刚才写完,使用看看先~
PATH=/sbin:/usr/sbin:/bin:/usr/bin; export PATH
accountfile="user.passwd"
# 1. 进行账号相关的输入先!
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
# 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
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
# 3. 开始建立账号与密码!
cat "$accountfile" | cut -d':' -f1 | xargs -n 1 useradd -m
chpasswd < "$accountfile"
pwconv
echo "OK!建立完成!"</span>
通过执行可以完成批量添加用户的功能。