shell batch create user

# ! / Bin / bash 
 
CAT << EOF
 **************************************** ******************** 
    bulk add users and eight randomly generated password string as its 
        www.tianfeiyu.com
 ************ ************************************************ 
EOF 
 
ADMIN Feiyu =      # define a prefix to be added to the user name 
 
[ -f /etc/init.d/functions] &&. /etc/init.d/functions || Exit 
 
 
for n- in $ (SEQ -w 10 )   
do 
    the passwd = `echo $ (DATE% T +% N) the rANDOM $ | the md5sum | Cut -C 1-8`    # generates a random password 
    ID ADMIN} {$ - $ & n-> / dev / null                     # determines whether the user is present
    [ $? -ne 0 ] && {
        useradd ${admin}-$n &> /dev/null && user_status=$?
        echo "$passwd"|passwd --stdin ${admin}-$n &> /dev/null && passwd_status=$?
    
        if [ "$user_status" == 0 -a "$passwd_status" == 0 ];then
            action "adduser ${admin}-$n" /bin/true
            echo -e "user:\t ${admin}-$n \t passwd:\t $passwd" >> ./user.txt  
        else
            action "adduser ${admin}-$n" /bin/false
            echo -e "user:\t ${admin}-$n \t passwd:\t $passwd" >> ./fail_user.txt
        fi
    } || 
    action "${admin}-$n is exist!" /bin/false
done

This batch script to add users, add the user name and password are saved in the current user.txt file in the directory.

 

 

 

Simple version

 

Guess you like

Origin www.cnblogs.com/betterquan/p/11595245.html