menu.sh 菜单界面脚本
#!/bin/bash
#menu.sh
function menu(){
cat << eof
#############################################
`echo -e "\033[32;40m menu \033[0m"`
#############################################
* 1)add a user
* 2)set password for user
* 3)delete a user
* 4)print disk space
* 5)print mem space
* 6)quit
* 7)return
#############################################
www.baibai.com `date +%Y-%m-%d`
#############################################
eof
}
index.sh 菜单功能脚本#!/bin/bash
#index.sh
. menu.sh
menu
read -p "please input a option:" option
case $option in
1)read -p "add a user:" name
useradd $name
if [ $? -eq 0 ];then
str="$name is created sucessfully!"
echo -e "\033[31;40m$str\033[0m"
else
str="$name is created unsucessfuly!"
echo -e "\033[31;40m$str\033[0m"
fi
;;
2)read -p "input a username:" name
read -p "set pass for user:" pass
echo $pass | passwd --stdin $name
if [ $? -eq 0 ];then
str="set passwd for $name sucessfully!"
echo -e "\033[31;40m$str\033[0m"
else
str="set passwd for $name unsucessfully!"
echo -e "\033[31;40m$str\033[0m"
fi
;;
3)read -p "dalete a user:" name
userdel -r $name
if [ $? -eq 0 ];then
str="delete $name sucess!"
echo -e "\033[31;40m$str\033[0m"
else
str="delete $name unsucessfully!"
echo -e "\033[31;40$str\033[0m"
fi
;;
4)str=`free -m`
echo -e "\033[33;40m$str\033[0m"
;;
5)str=`df -Th`
echo -e "\033[32;40m$str\033[0m"
;;
6)echo -e "\033[34;40m Quit sucessfully!!! \033[0m"
;;
7)clear
menu
esac