shell编程Linux中批量创建用户

if [ -f "accountfile"  ];then
mv $accountfile "$accountfile"`date +%Y%m%d`
fi
touch "$accountfile"

read -p "qianzhui: " username_start
read -p "weizhui: " nu_nu
read -p "start num:" nu_start
read -p "shuliang: " nu_amount

nu_end=$(($nu_start+$nu_amount-1))

for(( i=$nu_start; i<=$nu_end; i++))
do
        nu_len=${#i}
        nu_diff=$(($nu_nu-$nu_len))
        if [ "$nu_diff" != "0"  ];then
        nu_nn=00000000000
        nu_nn=${nu_nn:1:$nu_diff}
        fi
        account="$username_start""$nu_nn""$i"
        echo "$account":"$account">>$accountfile
done
cat "$accountfile" | cut -d':' -f1 | xargs -n 1 useradd
pwunconv
chpasswd < "$accountfile"
pwconv
echo "ok"
exit 0


你可能感兴趣的:(Linux)