Shell scripting: Implementing Linux User management and monitoring through the shell

Source: Internet
Author: User



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.sh
function 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: $ name Date: $ time ##
################################################ #####################
qaz
}
4.index.sh

#! / bin / bash
# index.sh
function index () {
clear
. menu.sh
menu
while true
do
read -p "Please input a option:" option
case $ option in
1)
read -p "Please input username:" name
useradd $ name &> / dev / null
if [$? -eq 0]; then
echo "user $ {name} is created successfully !!!"
else
echo "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:" name
read -p "set password for the user:" pass
echo $ pass | passwd --stdin $ name &> / dev / null
if [$? -eq 0]; then
str = "$ {name}‘ s password is set successfully "
echo -e "\ 033 [30; 47 $ str \ 033 [0m"
else
str = "$ {name}‘ s password is set failly !!! "
echo -e "\ 033 [31; 47m $ str \ 033 [0m"
fi
;;
4)
read -p "delete the user:" name
userdel -r $ name &> / dev / null
if [$? -eq 0]; then
str = "user $ {name} is delete successfully !!!"
echo -e "\ 033 [30; 47m $ str \ 033 [0m"
else
str = "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)
clear
menu
                ;;
8)
echo -e "\ e [31mLogout ... \ e [0m"
sleep 1
break
;;
                9)
                        echo -e "\ e [31mQuit successfully !!! \ e [0m"
                        exit
;;
*)
str = "Input error please re-enter"
echo -e "\ 033 [30; 47m $ str \ 033 [0m"
;;
esac
done
}
5.welcome.sh

#! / bin / bash
#welcome
clear
echo -e "\ e [31mWelcome \ e [0m"
while true
do
read -p ‘Please enter user name (Quit please input" q "):‘ name
if [$ name = "q"]
then
break
else
read -p ‘Please enter user password:’ password
if [$ name = ‘admin‘] && [$ password = ‘admin‘]
then
str = "Login successfully, Please Wait ......"
echo -e "\ e [31m $ str \ e [0m"
sleep 2
. index.sh
index
else
str = "Login failly"
echo -e "\ e [31m $ str \ e [0m"

fi
fi
done
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 keep this source http://guoxin2014.blog.51cto.com/4020074/1812435

Shell script: Linux user management and monitoring through the shell

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.