! # / bin / bash
#author: Li Kun
#date: 2019.8.28
#title: user management system
#author: Li Kun
#date: 2019.8.28
#title: user management system
echo "\\ // ============================="
echo "| user system |"
echo "----- ---------------------------- "
echo" |. @ @ 1 create a user | "
echo" |. @ @ 2 delete users | "
echo" |. @ 3 @ lock the user | "
echo" |. @ 4 @ unlock the user | "
echo" |. @ 5 @ View user | "
echo" |. @ @ 6 launch user | "
echo" --- ------------------------------ "
echo" ----------------- ---------------- "
# specific operations
while true
do
do
read -p "Enter Your Pick:" aaa
IF [$ aaa -eq 1]
the then
read -p "Please enter your new user name:" bbb
[-d / Home / $ bbb]
IF [$ -? 0 EQ]
the then
echo "the user already exists, please try again"
the else
useradd $ bbb &> / dev / null
the Read -p "Please enter your password:" ccc
echo "$ ccc" | passwd --stdin $ bbb
fi
IF [$ aaa -eq 1]
the then
read -p "Please enter your new user name:" bbb
[-d / Home / $ bbb]
IF [$ -? 0 EQ]
the then
echo "the user already exists, please try again"
the else
useradd $ bbb &> / dev / null
the Read -p "Please enter your password:" ccc
echo "$ ccc" | passwd --stdin $ bbb
fi
# Delete user
elif [$ aaa -eq 2]
the then
the Read -p "Please enter the user name you want to delete:" dd
[-d / Home / $ dd]
IF [? $ -Eq 0]
the then
userdel -r $ dd
echo "user deleted"
the else
echo "this user does not exist, please re-enter your user name to be deleted"
fi
elif [$ aaa -eq 2]
the then
the Read -p "Please enter the user name you want to delete:" dd
[-d / Home / $ dd]
IF [? $ -Eq 0]
the then
userdel -r $ dd
echo "user deleted"
the else
echo "this user does not exist, please re-enter your user name to be deleted"
fi
# Lock the user
elif [$ aaa -eq 3]
the then
the Read -p "Enter the user you want to lock:" GG
[-d / Home / $ GG]
IF [? $ -Ne 0]
the then
echo "user does not exist"
the else
IF [$ ($ GG the passwd -S | awk '{} Print $ 2') = "the PS"]
the then
the passwd -l $ GG &> / dev / null
echo "successfully locked"
Fi
Fi
elif [$ aaa -eq 3]
the then
the Read -p "Enter the user you want to lock:" GG
[-d / Home / $ GG]
IF [? $ -Ne 0]
the then
echo "user does not exist"
the else
IF [$ ($ GG the passwd -S | awk '{} Print $ 2') = "the PS"]
the then
the passwd -l $ GG &> / dev / null
echo "successfully locked"
Fi
Fi
# Unlock the user
elif [$ aaa -eq 4]
the then
the Read -p "Enter the name you want to unlock:" HH
[-d / Home / $ HH]
IF [? $ -Eq 0]
the then
echo "will unlock ,,, this operation is dangerous "
IF [$ (HH the passwd -S $ | awk '{} Print $ 2') =" LK "]
the then
the passwd -u HH & $> / dev / null
echo" release success !!!! "
the else
echo "the user has been lifted,"
fi
fi
# view the user
elif [$ aaa -eq 5]
the then
the Read -p "enter the user you want to check in:" tt
[-d / Home / $ tt]
IF [$? -eq 0]
the then
finger tt $
echo "Well, you found out !!"
the else
echo "user does not exist, you can not find your garbage !!!!"
fi
# launch script
elif [$ aaa -eq 6]
the then
IF [$? -eq 0]
the then
echo "There is no ending feast! goodbye! "
BREAK
the else
echo" you could not walk, baby, hey "
fi
fi
elif [$ aaa -eq 4]
the then
the Read -p "Enter the name you want to unlock:" HH
[-d / Home / $ HH]
IF [? $ -Eq 0]
the then
echo "will unlock ,,, this operation is dangerous "
IF [$ (HH the passwd -S $ | awk '{} Print $ 2') =" LK "]
the then
the passwd -u HH & $> / dev / null
echo" release success !!!! "
the else
echo "the user has been lifted,"
fi
fi
# view the user
elif [$ aaa -eq 5]
the then
the Read -p "enter the user you want to check in:" tt
[-d / Home / $ tt]
IF [$? -eq 0]
the then
finger tt $
echo "Well, you found out !!"
the else
echo "user does not exist, you can not find your garbage !!!!"
fi
# launch script
elif [$ aaa -eq 6]
the then
IF [$? -eq 0]
the then
echo "There is no ending feast! goodbye! "
BREAK
the else
echo" you could not walk, baby, hey "
fi
fi
done