Create a user and a corresponding random password

# / Bin / bash! 
"User-created:" echo> /root/jiao/username.txt 
the Read -ep "user input to be created:" NUM 
for i in `seq 1 $ num` 
do 
 pw =` CAT / dev / urandom | head -1 | the md5sum | head -C 5` 
 ID WG $ I> / dev / null 2> &. 1 
 IF [-eq $ 0?]; the then 
  the while to true 
  do 
   Read -ep "I WG $ user already exists, Remove this user (the y-/ the n-): "the SELECT 
   Case $ the SELECT in 
   the y-| the Y-) 
    userdel -rf wg $ i> / dev / null 
    echo" wg $ i deleted successfully " 
    BREAK 
   ;; 
   the n-| N) 
    BREAK 
   ;; 
   * ) 
    echo "input error, re-input" 
   Esac 
  DONE 
 the else 
  the useradd WG $ I> / dev / null 2> &1
  if [ $? -eq 0 ];then
   echo "wg $ i user has been created"
   echo "wg $ pw" | passwd --stdin wg $ i 
   echo "$ i $ wg pw" >> / root / username 
  the else 
   echo "User creation failed" 
  fi 
 fi 
DONE

 passwd --stdin standard input means

Guess you like

Origin www.cnblogs.com/lslyw/p/11598169.html