首页 > Web开发 > 详细

Shell脚本——监控web服务

时间:2018-03-27 16:31:16      阅读:238      评论:0      收藏:0      [点我收藏+]
1.监控端口

#!/bin/bash

##############################################################

# File Name: web.sh

# Version: V7.4

# Author: feng yu

# Organization: http://blog.51cto.com/13520761

# Created Time : 2018-03-27 15:05:09

# Description:

##############################################################

if [ $(netstat -lntup | grep -w  80| awk -F "[ :]+" 'NR==1{print $5}') = 80 ];then

    echo "Nginx is Running"

else

    echo "Nginx is Stopped"

    mail -s "Nginx is stop" q@163.com < nginx is stop

fi


2.监控进程(注意:监控进程,脚本名不要写服务名)

#!/bin/bash

##############################################################

# File Name: web1.sh

# Version: V7.4

# Author: feng yu

# Organization: http://blog.51cto.com/13520761

# Created Time : 2018-03-27 15:30:56

# Description:

##############################################################

if [ $(ps -ef | grep nginx |wc -l) -gt 0 ];then

    echo "Nginx is Running"

else

    echo "Nginx is stopped"

    mail -s "nginx is stop" q@163.com < nginx is stop

fi


3.返回值

#!/bin/bash

##############################################################

# File Name: web2.sh

# Version: V7.4

# Author: feng yu

# Organization: http://blog.51cto.com/13520761

# Created Time : 2018-03-27 16:01:40

# Description:

##############################################################

num=$(curl -I www.baidu.com -s -w %{http_code} -o /dev/null)

if [ $num = 200 ];then

    echo "网页正常"

else

    echo "$num"

    mail -s "网页异常" q@163.com < 网页异常,$num

fi


Shell脚本——监控web服务

原文:http://blog.51cto.com/13520761/2091656

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!