本帖最后由 lqph3387 于 2010-11-22 15:09 编辑
#!/bin/bash
. /etc/profile #设置环境变量
d=`date +%F%t%R`
if [ -e /tmp/tomcat.log ]
then
cat /dev/null > /tmp/tomcat.log
else
touch /tmp/tomcat.log
fi
/usr/local/bin/lynx -dump -error_file=/tmp/tomcat.log http://192.168.100.4:8080/UsersLogin.jsp > /dev/null # 获取状态
grep “STATUS=HTTP/1.1 200 OK” /tmp/tomcat.log > /dev/null
if [ $? == 0 ] #如果没问题
then
echo “=========================” >> /opt/tcstatus.log
echo “tomcat is ok at $d” >> /opt/tcstatus.log
echo >> /opt/tcstatus.log
else #如果有问题
pid=`ps aux |grep tomcat|awk '{print $2}'|sed '2d'`
if [ -n "$pid" ] #如果tomcat进程依然存在
then
pid=`ps aux |grep tomcat|awk '{print $2}'|sed '2d'`
kill -9 $pid
/usr/local/tomcat/bin/startup.sh
else #如果tomcat进程不存在了
/usr/local/tomcat/bin/startup.sh
fi
pid=`ps aux |grep tomcat|awk '{print $2}'|sed '2d'`
echo “=========================” >> /opt/tcstatus.log
echo “tomcat has been restarted at $d, new pid is $pid” >> /opt/tcstatus.log
echo >> /opt/tcstatus.log
echo “Please log on and check the tomcat log” | /bin/mail -s “hi,crm webserver has been restarted.” xxx@139.com
fi
exit 0
#!/bin/bash
. /etc/profile #设置环境变量
d=`date +%F%t%R`
if [ -e /tmp/tomcat.log ]
then
cat /dev/null > /tmp/tomcat.log
else
touch /tmp/tomcat.log
fi
/usr/local/bin/lynx -dump -error_file=/tmp/tomcat.log http://192.168.100.4:8080/UsersLogin.jsp > /dev/null # 获取状态
grep “STATUS=HTTP/1.1 200 OK” /tmp/tomcat.log > /dev/null
if [ $? == 0 ] #如果没问题
then
echo “=========================” >> /opt/tcstatus.log
echo “tomcat is ok at $d” >> /opt/tcstatus.log
echo >> /opt/tcstatus.log
else #如果有问题
pid=`ps aux |grep tomcat|awk '{print $2}'|sed '2d'`
if [ -n "$pid" ] #如果tomcat进程依然存在
then
pid=`ps aux |grep tomcat|awk '{print $2}'|sed '2d'`
kill -9 $pid
/usr/local/tomcat/bin/startup.sh
else #如果tomcat进程不存在了
/usr/local/tomcat/bin/startup.sh
fi
pid=`ps aux |grep tomcat|awk '{print $2}'|sed '2d'`
echo “=========================” >> /opt/tcstatus.log
echo “tomcat has been restarted at $d, new pid is $pid” >> /opt/tcstatus.log
echo >> /opt/tcstatus.log
echo “Please log on and check the tomcat log” | /bin/mail -s “hi,crm webserver has been restarted.” xxx@139.com
fi
exit 0
0
有几个看不太懂:
1、/usr/local/bin/lynx -dump -error_file=/tmp/tomcat.log http://192.168.100.4:8080/UsersLogin.jsp > /dev/null # 获取状态
2、awk '{print $2}'|sed '2d'`
这个脚本可以放入监控程序么?
1、/usr/local/bin/lynx -dump -error_file=/tmp/tomcat.log http://192.168.100.4:8080/UsersLogin.jsp > /dev/null # 获取状态
2、awk '{print $2}'|sed '2d'`
这个脚本可以放入监控程序么?
编辑回复