(a) Print a menu, accept an input, if there is no user to create a user and password, will create a user and password to write to a file, if there is a file to impersonate a user to log in, require the user name arbitrary, can be (^$ ^q), the password can be either a blank password, or any length of password.
The shell code is as follows:
#!/bin/bash
Create_user () {
Read-p "Plz Input name:" Name
Cat File | grep $name &>/dev/null
[$?-eq 0] && echo "The user is Exise" && exit 0
If [-Z $name];then
echo "No exise" && exit 0
Fi
Read-p "Plz Input Passwd:" Passwd
Read-p "Plz Input Passwd Again:" Passwd1
if [["$passwd"! = "$PASSWD 1"]]; then
echo "passwd not right" && exit 0
Fi
if [!-Z "$passwd"];then
echo "$name" $passwd "" >>file
echo "successfully!"
Fi
If [-Z ' $passwd '];then
echo "$name" "" >>file
echo "successfully!"
Fi
}
Login () {
Read-p "Plz Input name:" Name
A= "' Cat file | awk ' $1== ' $name ' "' |cut-d '-f2-'"
B= ' echo ' $a | Sed ' s///g '
Cat File | awk ' $1== ' $name ' "' &>/dev/null
If [$?-eq 0];then
Read-p "Plz Input your passwd:" passwd
C= ' echo $passwd | Sed ' s///g '
if [["$b" = "$c"]];then
echo "successfully!"
Else
echo Error
Fi
Else
echo "Not user;plz to Creiate"
Fi
}
Haha () {
Case $CC in
1)
Create_user
;;
2)
Login
;;
3)
Exit 0
;;
*)
Exit 1
;;
Esac
}
Cat << EOF
=========please choice=========
1) Create_user
2) Login
3) exit
Eof
Read-p "Choice:" CC
haha
Although this script is very simple, but I also according to different situation debugging for a long time.
This article is from the "It Life" blog, so be sure to keep this source http://dingxue.blog.51cto.com/12290895/1970428
Shell grooming (35) = = = = = = Script for the simulated User login print menu