! # / usr / bin / env bash ############################### # Script Name: userManager.sh # # Script function: account management # # script parameters: None # # created: 2019-07-25 # # author: Mr.Guo # # version: v1.0 # ############### ################ # message [] <- () note_message () { CAT << the EOF -------- ------ user manager ----- 1. Create user 2. delete user 3. lock user 4. unlock the user 5. script exits the EOF } # Create account [] <- (user: String, the passwd: String) create_user () { user = " 1 $ " pwd =" $ 2 " useradd" $ the User "Add account # echo" $ pwd "| passwd --stdin "$ User "# password IF [[ "? $" == 0]]; the then echo "user has successfully created" Exit fi } # Delete Account [] <- (the User: String) DELETE_USER () { the User = "$ 1" userdel "$ the User" # delete user IF [[ "$?" == 0]]; the then echo "has been deleted $ {user} user" Fi } # locking account [] <- (user: String) lock_user () { user = "$. 1" = $ STAT (the passwd -S "User $" | awk '{} Print $ 2') IF [[ "$ STAT" == "the PS"]]; the then the passwd -l "$ User" Fi IF [[ "$ STAT "==" LK "]]; the then echo"$ User has locked the user " Exit Fi } # Account Unlock [] <- (user: string ) unlock_user () { User =" $. 1 " STAT = $ (the passwd -S "User $" | awk '{} Print $ 2') IF [[ "$ STAT" == "LK"]]; the then the passwd -u "$ User" Fi IF [ [ "$ STAT" == "PS"]]; the then echo "unlocked the User account $" exit fi } # exit script [] <- () exit_script () { the Read -p "whether to exit the script (yes)" tu IF [[ "$ TU" == "Yes"]]; the then Exit Fi } # main function [] <- () main () { note_message # message read -p "Please input operation (1-5): "sn Case" $ sn "in 1) the Read -p" enter need to create a user name:"Uname the Read -p" Please set a password to the account: "passwduname create_user "$uname" "$passwd" ;; 2) read -p "Enter the user name to be deleted:" uname DELETE_USER "$ uname" ;; 3) read -p "Please enter the user name needs to be locked in:" uname lock_user "$ uname" ;; 4) read -p " enter the user name you want to unlock: "uname unlock_user" $ uname " ;; 5) printf" to exit the script \ the n-" exit_script ;; esac } # function runs main