本帖最后由 820009174 于 2016-7-8 19:00 编辑
实验环境:青云云主机
step1:yum install -y sendmail mail dos2unix
/etc/init.d/sendmail start
step2:脚本内容
vim auto_monitor_service.sh
#! /bin/bash
#auto monitor server
#by author GuoKang
EMAIL=email.txt
#[1m 表示下面所有的内容都要改变颜色
echo -e "\033[32m \033[1m"
if [ -f $1 -a "$1" == "list.txt" ];then
for i in `cat list.txt|grep -v "#"`
do
count=`ps -ef|grep $i|grep -v email|grep -v grep|wc -l`
M_IPADDR=`ifconfig |sed -n 2p |awk '{print $2}'|cut -f 2 -d:`
DATE=`date`
if [ $count -eq 0 ];then
cat >$EMAIL <>/dev/null 2>&1
else
echo "The $i server 200 ok!"
fi
done
else
count=`ps -ef|grep $1|grep -v email|grep -v grep|wc -l`
M_IPADDR=`ifconfig |sed -n 2p |awk '{print $2}'|cut -f 2 -d:`
DATE=`date`
if [ $count -eq 0 ];then
cat >$EMAIL <>/dev/null 2>&1
else
echo "The $1 server 200 ok!"
fi
fi
==================================
vim list.txt
#server monitor list
nginx
mysql
redis
httpd
nfs
keepalived
memcached
==================================
yum install -y httpd
/etc/init.d/httpd start
step3:脚本测试
[root@i-e8k7bbvc ~]# sh auto_monitor_service.sh list.txt
dos2unix: converting file email.txt to UNIX format ...
The monitor nginx Warning,Please Check.
dos2unix: converting file email.txt to UNIX format ...
The monitor mysql Warning,Please Check.
dos2unix: converting file email.txt to UNIX format ...
The monitor redis Warning,Please Check.
The httpd server 200 ok!
dos2unix: converting file email.txt to UNIX format ...
The monitor nfs Warning,Please Check.
dos2unix: converting file email.txt to UNIX format ...
The monitor keepalived Warning,Please Check.
dos2unix: converting file email.txt to UNIX format ...
The monitor memcached Warning,Please Check.
实验环境:青云云主机
step1:yum install -y sendmail mail dos2unix
/etc/init.d/sendmail start
step2:脚本内容
vim auto_monitor_service.sh
#! /bin/bash
#auto monitor server
#by author GuoKang
EMAIL=email.txt
#[1m 表示下面所有的内容都要改变颜色
echo -e "\033[32m \033[1m"
if [ -f $1 -a "$1" == "list.txt" ];then
for i in `cat list.txt|grep -v "#"`
do
count=`ps -ef|grep $i|grep -v email|grep -v grep|wc -l`
M_IPADDR=`ifconfig |sed -n 2p |awk '{print $2}'|cut -f 2 -d:`
DATE=`date`
if [ $count -eq 0 ];then
cat >$EMAIL <>/dev/null 2>&1
else
echo "The $i server 200 ok!"
fi
done
else
count=`ps -ef|grep $1|grep -v email|grep -v grep|wc -l`
M_IPADDR=`ifconfig |sed -n 2p |awk '{print $2}'|cut -f 2 -d:`
DATE=`date`
if [ $count -eq 0 ];then
cat >$EMAIL <>/dev/null 2>&1
else
echo "The $1 server 200 ok!"
fi
fi
==================================
vim list.txt
#server monitor list
nginx
mysql
redis
httpd
nfs
keepalived
memcached
==================================
yum install -y httpd
/etc/init.d/httpd start
step3:脚本测试
[root@i-e8k7bbvc ~]# sh auto_monitor_service.sh list.txt
dos2unix: converting file email.txt to UNIX format ...
The monitor nginx Warning,Please Check.
dos2unix: converting file email.txt to UNIX format ...
The monitor mysql Warning,Please Check.
dos2unix: converting file email.txt to UNIX format ...
The monitor redis Warning,Please Check.
The httpd server 200 ok!
dos2unix: converting file email.txt to UNIX format ...
The monitor nfs Warning,Please Check.
dos2unix: converting file email.txt to UNIX format ...
The monitor keepalived Warning,Please Check.
dos2unix: converting file email.txt to UNIX format ...
The monitor memcached Warning,Please Check.
编辑回复