#!/bin/bash
#批量创建用户并设置密码

if [ ! -f "userlist.txt" ];then
  echo "!!userlist is not exist,please check!!"
  exit 10
fi
user_file=`cat userlist.txt`
#pass=`head -c 20 /dev/urandom | base64 | cut -c 5-19`
for i in $user_file;do
  useradd $i &>/dev/null
  if [ $? -eq 0 ];then
    echo "$i set success"
  else
    echo "!!$i is failed to create,please check!!"
    continue
  fi

  for A in `head -c 20 /dev/urandom | base64 | cut -c 5-19`;do
    echo  $i password: $A >> passlist.txt
    echo "$A" | passwd --stdin $i &>/dev/null
  done
done
echo "please view password in passlist.txt"
