服务进程和流量检测,web界面检查(shell)

#!/bin/bash
export base_dir=`pwd`
export IP=`ifconfig|grep "inet addr:"|awk '{print $2}'|head -n 1|awk -F ":" '{print $2}'`
export time=`date +"%Y%m%d%H%M"`
chechpr(){
#判断服务进程是否存在
pid=`ps -ef|grep tomcat|grep -v grep|awk '{print $2}'`
if [ $? -eq 0 ];then
if [ -n "$pid" ];then
echo "tomcat is alived"
else
echo "tomcat service is not running!">>/$base_dir/$IP\_$time.log
fi
else 
echo "ps command run failed!!!">>/$base_dir/$IP\_$time.log
exit 1
fi
#服务流量监测,是否有tcp连接进入
port=`netstat -antp|grep "ESTABLISHED"|grep "8080"`
if [ $? -eq 1 ];then
if [ -s "$port" ];then
echo "tomcat is alived"
else 
echo "tomcat is not tcp conncent ">>/$base_dir/$IP\_$time.log
fi
else 
echo "netstat command run failed!!!">>/$base_dir/$IP\_$time.log
exit 1
fi
#监测web界面是否正常;
curl "http://x.x.x.x:8080"
if [ $? -eq 0 ];then
echo "web is ok"
else
echo "web is can not conncent!!!">>/$base_dir/$IP\_$time.log
fi
}
checkfile(){
#如果服务进程异常,将相关信息cp到跳板机对应日期目录下面。
cd /$base_dir
if [ $? -eq 0 ];then
if [ -n "$IP\_$time.log" ];then
date=`date +%Y%m%d`
scp $IP\_$time.log root@x.x.x.x:/home/$date/
if [ $? -eq 0 ];then
echo "scp is ok"
else
echo "scp command run failed"
mail -s "scp command run failed"  xxxxxxx@qq.com < /$base_dir/$IP\_$time.log
fi
else 
echo "service is ok"
fi
else 
echo "cd command run failed">>/$base_dir/$IP\_$time.log
exit 1
fi
}
chechpr
checkfile

转载于:https://my.oschina.net/u/3246484/blog/1545433

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值