Learn the first script from the shell, thanks to cloud Li Qiangqiang Teacher's shell programming tutorial
To create a shell script file:
Touch menu.sh
Touch index.sh
Touch welcome.sh
To give the script file permission to execute:
chmod a+x menu.sh index.sh welcome.sh
menu.sh
#!/bin/bash#menu.shfunction menu () {title= "my home" name= "Randy" Time= ' date +%y-%m-%d ' cat << qaz######################################################################### *** ' echo -e "\e[32m $title \e[0m" ' * * * ############################################################## ############ #1) add a user ### #2) view all users ### #3) Set passwd for user ### #4) delete a user ### #5) print disk space ### #6) print mem space ### #7) retrun menu ### #8) logout ### #9) Quit ############################################# ############################## name: $nameDate: $time ############ ############################################################ #qaz}
4.index.sh
#!/bin/bash#index.shfunction index () {clear. menu.shmenuwhile truedoread -p " Please input a option: " optioncase $option in1) read -p " please Input username: " nameuseradd $name &>/dev/nullif [ $? -eq 0 ];thenecho "user ${name} is created successfully!!!" elseecho "user ${name} is created failly!!!" fi;; 2) str= ' cat /etc/passwd | awk -f: ' {print $1} ' echo -e ' \e[32m$str\e[0m ";; 3) read -p "Input the username:" nameread -p "set password for the user: " passecho $pass | passwd --stdin $name &>/dev/ Nullif [ $? -eq 0 ];thenstr= "${name} ' s password is set Successfully "echo -e " \033[30;47$str\033[0m "elsestr=" ${name} ' s password is&Nbsp;set failly!!! " echo -e "\033[31;47m$str\033[0m" FI;; 4) read -p "Delete the user:" nameuserdel -r $name &>/dev/nullif [ $? -eq 0 ];thenstr= "user ${name} is delete successfully!!!" echo -e "\033[30;47m$str\033[0m" elsestr= "user ${name} is delete failly!!!" echo -e "\033[31;47m$str\033[0m" fi ;; 5) str= ' df -th ' echo -e "\033[30;47m$str\033[0m";; 6) str= ' free -m ' echo -e "\033[30;47m$str\033[0m" ;; 7) clearmenu ;; 8) echo -e "\e[31mlogout ...\e[0m" sleep 1break;; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;9) echo -e "\e[31mquit successfully!!! \e[0m " exit;; *) str= "Input error please re-enter" echo -e "\033[30;47m$str\033[0m";; Esacdone}
5.welcome.sh
#!/bin/bash#welcomeclearecho-e "\e[31mwelcome\e[0m" while Truedoread-p ' please enter the user name (Quit please input "q"): ' Nameif [$name = "Q"]thenbreakelseread-p ' Please enter user password: ' passwordif [$name = ' admin '] && [$pas Sword = ' admin ']thenstr= "Login successfully,please Wait ..." echo-e "\e[31m$str\e[0m" Sleep 2. Index.shindexelsestr= " Login failly "echo-e" \e[31m$str\e[0m "Fifidone
6. Interface Display:
650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M01/83/DE/wKiom1d-XNrR4jb0AAJsrLezAKM980.jpg-wh_500x0-wm_3 -wmp_4-s_976144196.jpg "title=" shell.jpg "alt=" Wkiom1d-xnrr4jb0aajsrlezakm980.jpg-wh_50 "/>
This article is from the "Guo Xin Technology Blog" blog, please be sure to keep this source http://guoxin2014.blog.51cto.com/4020074/1812437
Shell Scripting Learning Notes: Implementing Linux User management and monitoring through the shell