
if ps -ef | grep "nginx"|egrep -v grep > /dev/null
then
echo ok!
else
systemctl start nginx //添加自己的启动命令同样也适用于其他的服务
fi
本文介绍了一种使用shell脚本检查Nginx服务是否运行的方法。通过组合使用ifps、grep、egrep和systemctl命令,可以实现对Nginx服务状态的自动检测,并在服务未运行时自动启动。

if ps -ef | grep "nginx"|egrep -v grep > /dev/null
then
echo ok!
else
systemctl start nginx //添加自己的启动命令同样也适用于其他的服务
fi
3130

被折叠的 条评论
为什么被折叠?