一个简单的监控web服务的shell脚本
-
监控说明:
-
创建:
#! /bin/bash web_hosts=(192.168.178.52:1000 192.168.178.53:2000) today_time=`date '+%F %H:%M:%S_week-%w'` to_email=1095322098@qq.com systemctl restart sendmail if [ `echo $?` -ne 0 ];thenecho "无sendmail服务"exit fi for host_port in ${web_hosts[*]};doecho ${host_port}host=`echo ${host_port} | awk -F':' '{print $1}'`ping -c 5 ${host} &> /dev/nullif [ `echo $?` -ne 0 ];thenecho "${host} 服务器网络异常"echo "${today_time}发现: ${host}服务器网络异常" | mail -s "网络警告" ${to_email} &> /dev/nullficurl --connect-timeout 30 ${host_port} &> /dev/nullif [ `echo $?` -ne 0 ];thenecho "${host_port} web服务异常"echo "${today_time}发现: ${host_port}web服务异常" | mail -s "服务警告" ${to_email} &> /dev/nullfi done