/tmp/down_countficurl-Itomcat-host-o"/tmp/sta..." />
 手机
当前位置:查字典教程网 >脚本专栏 >linuxshell >自动重启服务的shell脚本代码
自动重启服务的shell脚本代码
摘要:复制代码代码如下:#!/bin/bashif[!-f/tmp/down_count];thenecho"0">/tmp/down_count...

复制代码 代码如下:

#!/bin/bash

if [ ! -f /tmp/down_count ];then

echo "0" > /tmp/down_count

fi

curl -I tomcat-host -o "/tmp/status" >/dev/null 2>&1

code=`awk 'NR==1 {print $2}' /tmp/status`

if [ "$[code]" -ge 500 ];then

down=`expr $(cat /tmp/down_count) + 1`

echo "$down" > /tmp/down_count

if [ "$down" -gt 3 ];then

if [ ! -f "/tmp/restart_count" ];then

echo "0" > /tmp/restart_count

fi

restart_count=`expr $(cat /tmp/restart_count) + 1`

echo "$restart_count" > /tmp/restart_count

if [ "$restart_count" -le 2 ];then

echo "tomcat down at `date`" >> /tmp/down_info

/etc/init.d/tomcat6 restart

fi

fi

else

echo "0" > /tmp/down_count

echo "0" > /tmp/restart_count

fi

脚本实现了,当检测网页状态码大于等于500连续出现3次数,自动重启tomcat6,且只连续重启两次。

【自动重启服务的shell脚本代码】相关文章:

shell脚本学习与总结

查找目录下同名但不同后缀名文件的shell脚本代码

统计网卡流量的两段shell脚本(使用ifconfig)

统计 cpu 内存 使用率的shell脚本代码

用expect实现的自动登录到多台服务器的shell脚本

linux下自动备份MySQL数据并上传到FTP上的shell脚本

ssh expect自动登录的脚本代码

备份shell脚本实例代码

shell 进度条实现代码

监控php-fpm并自动重启服务的shell脚本

精品推荐
分类导航