700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > shell脚本监控nginx的运行状态

shell脚本监控nginx的运行状态

时间:2021-12-14 12:24:23

相关推荐

shell脚本监控nginx的运行状态

监控逻辑为:监控nginx端口状态是否正常 以及 nginx进程号是否存在

监控脚本名称为nginx_monitor.sh,脚本内容如下

#!/bin/sh

MONITOR_LOG=/home/gavin2/scripts/log/nginx_monitor.log

nginx_monitor()

{

#nginx的端口号

PORT=“80”

#获取nginx端口监听状态,如果nginx正常运行,PORT_FLAG值为0

PORT_STATUS=$(netstat -plnt|grep $1|grep ${PORT})

#获取上一个命令的退出状态,正常退出为0

PORT_FLAG=$?

#使用管道命令查询nginx的进程号

NGINX_STATUS=$(ps -ef |grep $1|grep -v ‘grep’|grep master|awk ‘{print $2}’)

#如果进程号存在并且端口监听正常,则说明nginx正常运行

if [ ${NGINX_STATUS} ] && [ ${PORT_FLAG} = “0” ];then

echodate "+%Y/%m/%d %H:%M:%S $1 is running">>${MONITOR_LOG} 2>&1

else/post-191232-bec4a1fb6a574fdf806c9eaf8e9aa8e1-1.shtml

echodate "+%Y/%m/%d %H:%M:%S [error] $1 has already shutdown">>${MONITOR_LOG} 2>&1

fihttp:/

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。