Bulk create 10 system account, and set a password (the password is a random number, required mix of characters and numbers (second)

! # / bin / bash 
echo "Creating a successful user"> / root / user_name 
the Read -ep "user input to be created:" NUM 
 
for i in `seq 1 $ num` 
do 
   pw =` CAT / dev / null / uradom | head -1 | the md5sum | head -C 5` 
   ID WG $ I> / dev / null & 2. 1 
   iF [-eq $ 0?]; the then 
     echo "the user exists" 
     Read -ep "delete this user (y / n ): "the SELECT 
     Case $ the SELECT in 
     the y-| the Y-) 
       userdel -rf wg $ i> / dev / null 
       echo" wg $ i deleted successfully " 
     ;; 
     the n-| N) 
       the Continue 
     ;; 
     *) 
       echo" enter the character is incorrect, re input " 
     Esac 
   the else 
     the useradd WG $ I> / dev / null 2> &. 1 
     IF [-eq $ 0?];the then 
       echo "$ i wg users to create success."
       echo "wg $ IPW" | passwd --stdin wg $ i 
       echo "$ i $ wg pw" >> / root / user_name 
     the else 
       echo "User creation failed" 
     fi 
   fi 
DONE

  

Guess you like

Origin www.cnblogs.com/luyuheng/p/11640454.html