Use a shell script to make user login system

The effect is as follows:

 

 

 

#!/bin/bash
#

to true the while
do
CAT << EOF
// ====================== \\\\
| user login system |
---------- ----------------
| 1, create a user |
| 2, delete the user |
| 3, lock the user |
| 4, unlock the user |
| 5, view the user |
| 6, exit script |
--------------------------
EOF

read -p "Please enter your OS choice:" NUM
# input to determine the time of 1
IF [ "$ NUM" -eq 1]
the then
read -p "Please enter your user name:" the User
IF [-d / Home / $ the User]
the then
echo "*********** the account already exists, without creating *************"
the else
CAT / etc / Shadow | awk -F ' [:] '' Print {$ 1} '| grep -w $ the User &> / dev / null
IF [? $ -eq 0]
the then
echo "*********** the account already exists, no Creating ************* "
the else
useradd the user $
echo" *********** successfully create user $ user ************* ** "
fi
fi
fi
# input to determine when the 2
IF [" $ NUM "-eq 2]
the then
the Read -p" Please enter your username: "user
if [ -d /home/$user ]
then
userdel -r $user
echo "****************** successfully removed the User **************** user $"
the else
echo "***** *********** without the account, delete failed ******************* "
fi
fi

# 3 input
IF [ "$ NUM" -eq 3]
the then
the Read -p "Please enter your user name:" the User
L = $ (CAT / etc / Shadow | grep $ the User | awk -F '[:] '' / !! / Print $ {2} '| grep -o' !! ')
IF [-d / Home / User $]
the then
IF [! "$ L" = !!]
the then
the passwd -l User & $> / dev / null
echo "***************** successfully locked the user **************** user $"
the else
echo "** ************* the account is locked, no lock ******************* "again
fi
the else
echo" ***** ********* account without the need to create ************ "
fi

be

# Input 4:00

IF [ "$ NUM" -eq 4]
the then
the Read -p "Please enter your user name:" the User
L = $ (CAT / etc / Shadow | grep -w $ the User | awk -F '[:]' '/ !! / Print $ {2} '| grep -o' !! ')
P = $ (CAT / etc / Shadow | grep -w User $ | awk -F' [:] '' Print $ {2} '| grep - O '^!')
IF [-d / Home / User $]
the then
IF [ "$ L" = !!]
the then
the passwd -u -f $ User &> / dev / null
echo "******* *************** successfully unlocked the user ************************ user $ "
elif [" the p-$ "=!]
the then
the usermod -U $ the user &> / dev / null
the else
echo" ***************** the user is not locked, without unlocking ******* ********** "
fi
the else
echo"*********************** account without the need to create ********************* * "
fi
fi

# Input is 5

IF [ "$ NUM" -eq 5]
the then
the Read -p "Please enter your user name:" the User
IF [-d / Home / $ the User]
the then
echo "************* ***** user $ user information is as follows *************************** "
finger $ user
the else
echo" ****** ***************** account without the need to create ********************** "
fi
fi

# Input is 6

IF [ "$ NUM" -eq 6]
the then
echo "************************** Welcome, see you next time ***** ********************* "
Exit
fi
DONE

Guess you like

Origin www.cnblogs.com/yuan9910/p/11445802.html