#!/bin/bash
nginx=/usr/local/nginx/sbin/nginx
read -ep “请输入要执行的命令(start stop status reload):” str
case $str in
start)
#检测nginx是否启动
netstat -nlpt | grep nginx &> /dev/null
if [ $? -eq 0 ];then
echo “nginx已经启动!”
else
echo “开始启动nginx!”
$nginx
fi
;;
#停止nginx
stop)
$nginx -s stop
#判断nginx是否停止
if [ $? -eq 0 ];then
echo “nginx已经停止运行!”
else
echo “nginx停止失败,请重试!”
fi
;;
status)
netstat -nlpt | grep nginx &> /dev/null
if [ $? -eq 0 ];then
echo “nginx已经启动!”
else
echo “nginx没有运行!”
fi
;;
reload)
$nginx -s reload
if [ $? -eq 0 ];then
echo “nginx重载成功!”
else
echo “nginx重载失败,请重试!”
fi
;;
*)
echo “请按提示正确输入!”
;;
esac
shell编写判断nginx
最新推荐文章于 2022-05-14 11:11:14 发布