1. ------------------------------脚本内容-----------------------------------
    #!/bin/bash
  2. shopt -s -o nounset
  3. ACTfile=${1:?'error,please input the account file!'}
  4. [ ! -f "$ACTfile" ] && echo "account file $ACTfile not exist." && exit 1
  5. declare -i okact=0
  6. act=''
    actpass=''
  7.  
  8. while read act actpass
  9. do
  10.         useradd $act
  11.         if [ $? -eq 0 ];then
  12.         echo "$act:$actpass" | chpasswd
  13.         ((okact++))
  14.         echo "account $act add successed"
  15. fi
  16. done < <(awk 'BEGIN{FS=":"} /\w:\w/ {print $1,$2}' $ACTfile)
  17. echo "add $okact users"
  18. -------------------------------------------------------------------------
  19. ./useradd.sh users.txt #####users.txx里面的格式是username:password