/tmp/down_count fi curl -I tomcat-host -o "/tmp/status" >/dev/null 2>&1 code=`awk 'NR==1 {" />

编程语言


自动重启服务的shell脚本代码

网络编程 自动重启服务的shell脚本代码 06-22

#!/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,且只连续重启两次。

linux下监视进程 崩溃挂掉后自动重启的shell脚本
=================================================本文为khler原作,转载必须确保本文完整并完整保留原作者信息及本文原始链接Author:HeYuanHuiE-mail:khler@163.comQQ:23381103

如何调试Linux shell脚本
shell也有一个真实的调试模式。如果在脚本"strangescript"中有错误,您可以这样来进行调试:sh-xstrangescript这将执行该脚本并显示所有变量的值。shell还有

用shell脚本实现自动切换内网和外网实现高可用
首先说明下我们的配置文件,都是类似格式的,假如内网是192.168.0.3,外网是123.123.123.123,配置文件如下:$db['salver']['hostname']='192.168.0.3:3306';//$db['salver']


编辑:编程语言

标签:脚本,本文,配置文件,内网,都是