Shell grooming (35) = = = = = = Script for the simulated User login print menu

Source: Internet
Author: User

(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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.