Skip to content

Instantly share code, notes, and snippets.

@binjoo
Last active July 29, 2019 01:14
Show Gist options
  • Save binjoo/77cb9882cbb7afd72c80e1ca39350701 to your computer and use it in GitHub Desktop.
Save binjoo/77cb9882cbb7afd72c80e1ca39350701 to your computer and use it in GitHub Desktop.
Shell脚本监控httpd服务80端口状态
# 这里是举例监控httpd服务端口状态,根据端口判断服务器是否启动,
# 如果没有启动则脚本自动拉起服务,如果服务正在运行则退出脚本程序;
# 如果换成别的服务端口也可以,但是脚本程序需要做调整。
#!/bin/bash
#实时每隔3秒监控HTTP服务状态,服务异常输出报警信息,并尝试启动,服务正常时提示正常运行。
web=`netstat -ant | grep 80 | awk '{print $4}' | awk -F : '{print $4}'`
apachelog=/var/log/httpd/service.log
if [ '$web' = '80' ]
then
echo "HTTPD正在运行"
else
echo "Web服务重新启动"
echo "`date` Web服务重新启动" >> $apachelog
/etc/init.d/httpd start &> /dev/null
sleep 2
echo `date` 重新启动 | /usr/sbin/sendmail -v [email protected] > /dev/null
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment