#!/bin/bash
#menu.sh
function menu() {
title="My Menu"
url="www.xhope.top"
time=`date +%Y-%m-%d`
cat << eof
#############################################
`echo -e "\033[32;40m$title\033[0m"`
#############################################
* 1) Add a user
* 2) Set password for user
* 3) Delete a user
* 4) Print disk space
* 5) Print men space
* 6) Quit
* 7) Return main menu
#############################################
$url $time
#############################################
eof
}
#!/bin/bash
#index.sh
. menu.sh #include menu.sh
clear
menu #call menu function
while [[ true ]]; do
read -p "Please type a option:" option
#echo $option
case $option in
1 )
read -p "Please type username:" username
useradd $username &>/dev/null
if [[ $? -eq 0 ]]; then
echo "user $username is created successfully"
else
echo "user $username is created failed"
fi
;;
2 )
read -p "Please type pass username:" name
read -p "Please type password:" pass
echo $pass | passwd --stdin $name &>/dev/null
if [[ $? -eq 0 ]]; then
echo "user $username password set successfully"
else
echo "user $username password set failed failed"
fi
;;
3 )
read -p "Please type username:" username
userdel -r $username &>/dev/null
if [[ $? -eq 0 ]]; then
echo "user $username is deleted successfully"
else
echo "user $username is deleted failed"
fi
;;
4 )
str=`df -Th`
echo -e "\033[30;47m$str\033[0m"
;;
5 )
str=`free`
echo -e "\033[30;47m$str\033[0m"
;;
6 )
echo -e "\033[30;47mQuit successfully!!\033[0m"
break
;;
7 )
clear
menu
;;
esac
done
- Shell界面
