批量创建10个系统帐号name01-name10并设置密码(密码为随机8位字符串

脚本

#!/bin/bash
. /etc/init.d/functions

[ $UID -ne 0 ] && {
echo "only allow root to exec this cmd."
exit 1
}

for n in seq -w 10
do
pass="$(echo $RANDOM|md5sum|cut -c 2-9)"
useradd name$n &>/dev/null &&\
echo $pass|passwd --stdin name$n &>/dev/null
if [ $? -eq 0 ];then
action "useradd name$n" /bin/true
else
action "useradd name$n" /bin/false
fi
echo -e "name$n\t$pass" >> user.txt
done

注:数字前加0的方法:
seq  -w 00 10;
echo  {01..10}