- ------------------------------脚本内容-----------------------------------
#!/bin/bash - shopt -s -o nounset
- ACTfile=${1:?'error,please input the account file!'}
- [ ! -f "$ACTfile" ] && echo "account file $ACTfile not exist." && exit 1
- declare -i okact=0
- act=''
actpass='' - while read act actpass
- do
- useradd $act
- if [ $? -eq 0 ];then
- echo "$act:$actpass" | chpasswd
- ((okact++))
- echo "account $act add successed"
- fi
- done < <(awk 'BEGIN{FS=":"} /\w:\w/ {print $1,$2}' $ACTfile)
- echo "add $okact users"
- -------------------------------------------------------------------------
- ./useradd.sh users.txt #####users.txx里面的格式是username:password
转载于:https://blog.51cto.com/loveroot/1102673