Shell脚本——监控web服务

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" [email protected] < 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" [email protected] < 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 "网页异常" [email protected] < 网页异常,$num

fi

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

时间: 2024-07-30 13:10:00

Shell脚本——监控web服务的相关文章

Shell脚本监控WEB服务是否正常

Step1.安装sendmail来发邮件 # yum -y install sendmail # /etc/init.d/sendmail start # chkconfig sendmail on Step2.安装mutt邮件客户端,并设置相关信息 # yum -y install mutt # vim /etc/Muttrc set charset="utf-8"           #设置发邮件编码 set envelope_from=yes set rfc2047_parame

shell 实现监控Web服务状态

使用shell 实现监控Web服务状态 原理:下载网站,并把输出写入 /dev/null,如果该命令执行结果成功(返回0)打印成功提示,如果下       载失败,这再下载一次,如果还是失败,就打印失败 脚本如下 [[email protected] ~]# cat checkurl.sh  #!/bin/bash CheckUrl(){ timeout=5 fails=0 success=0 while true   do     wget --timeout=$timeout --tries

linux运维学习shell脚本监控nginx服务

菜鸟学习shell脚本后,动手练手简单小实验,使用shell脚本判断nginx是否正常运行,如果没有运行将nginx服务启动起来. 一.基于进程判断 1.获取nginx进程来判断该服务是否正常启动. ps -ef | grep nginx | grep -v grep | wc -l    输出进程行数 然后判断是否为2 如果不是说明该服务没有启动. grep -v grep  用来排除掉您所使用grep产生的进程. 2.shell 脚本编写 先定义一个变量Web #!/bin/bash Web

用shell脚本监控linux系统 自动发送邮件

此脚本可以做一个定时的检测,超出设定的值,即往邮箱发送警告 脚本用到bc,sendmail,163邮箱, yum install bc #!/bin/bash #System Monitoring Script while [ 1 ] do #本机需开启postfix或sendmail服务. #报警邮件地址设置 [email protected] [email protected] #设置脚本运行间隔时间.单位(秒). RUNTIME=900 #内存使用率监控设置,单位 (%) MEMTHRE=

使用shell脚本监控少量服务器并发送微信告警信息

01. 概括 1.0 脚本更新地址Git更新地址:shell_monitor_script.sh文章原文地址:使用shell脚本监控少量服务器并发送微信告警信息 1.1 前提:平台系统:linux系统下接收信息:微信企业号 1.2 脚本说明需要修改微信接口脚本对应参数的修改:包括IP,告警阈值等 1.3 脚本使用该脚本监控包括Disk.CPU.MEM.LOAD等主机资源,以及docker服务和docker容器.将该脚本附件假定放于:/home/mai/.check_host.sh.那么在定时任务

Linux下shell脚本监控Tomcat的状态并实现自动启动

最近公司需要在Linux下监控tomcat的服务,一旦tomcat服务存在异常或者宕机,重启tomcat保证服务的正常运行,由于Linux下有Shell脚本可以实现此效果,下面是Linux下shell脚本监控Tomcat的状态并实现自动启动的步骤. 1.编写Shell脚本monitor.sh #!/bin/sh # func:自动监控tomcat脚本并且执行重启操作# author:EagleHao# date:2018-04-08# DEFINE # 获取tomcat进程ID(其中[grep

Shell脚本安装成服务加入系统启动-service XX does not support chkconfig

背景:Shell脚本是linux运维人员必备利器,怎么样把shell脚本安装成服务且加入系统启动,然后就可以使用服务来管理,这是一个很重要的问题. 当我们运行安装服务的命令时候,假设服务名为myservice #chkconfig --add myservice 常常会出现 service myservice does not support chkconfig 下面讲解正确方法: 1.1给服务脚本添加注释. #vim /etc/init.d/myservice 添加下面两句到 #!/bin/b

【转载】用shell脚本监控进程是否存在 不存在则启动的实例

用shell脚本监控进程是否存在 不存在则启动的实例,先上代码干货: #!/bin/shps -fe|grep processString |grep -v grepif [ $? -ne 0 ]thenecho "start process....."elseecho "runing....."fi#####processString 表示进程特征字符串,能够查询到唯一进程的特征字符串0表示存在的$? -ne 0 不存在,$? -eq 0 存在 ---------

用shell脚本监控进程是否存在 不存在则启动的实例附带if判断详细条件

#!/bin/shps -fe|grep processString |grep -v grepif [ $? -ne 0 ]thenecho "start process....."elseecho "runing....."fi#####processString 表示进程特征字符串,能够查询到唯一进程的特征字符串0表示存在的$? -ne 0 不存在,$? -eq 0 存在 --------------------------------------------