#!/bin/bash
menu()
{
echo "---欢迎使用mysql管理服务程序---"
echo "# 1.启动服务"
echo "# 2.停止服务"
echo "# 3.重启服务"
echo "# 4.查看状态"
echo "# 5.退出程序"
echo "-----------------------------"
}
choice()
{
read -p "Please choice a menu[1‐9]:" select
}
start(){
pid=`netstat -antp | grep -i "listen" | grep -i "3306" | awk '{print $7}' | awk -F"/" '{print $1}'`
if [ ! -n "$pid" ]
then
service mysqld start
else
echo "mysql is running"
fi
}
stop(){
pid=`netstat -antp | grep -i "listen" | grep -i "3306" | awk '{print $7}' | awk -F"/" '{print $1}'`
if [ ! -n "$pid" ]
then
echo "mysql is stoped"
else
kill -9 $pid
fi
}
restart(){
stop
sleep 1
start
}
status(){
pid=`netstat -antp | grep -i "listen" | grep -i "3306" | awk '{print $7}' | awk -F"/" '{print $1}'`
if [ ! -n "$pid" ]
then
echo "mysql is stoped"
else
echo "mysql is running"
fi
}
while :
do
menu
choice
case $select in
1)
start;;
2)
stop;;
3)
restart;;
4)
status;;
5)
exit;;
*)
echo "您输入的数字没有对应的菜单"
esac
done
Linux记录
点赞
收藏