shell脚本监控Tomcat并重启发送短信
Posted kankankankankan
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了shell脚本监控Tomcat并重启发送短信相关的知识,希望对你有一定的参考价值。
#!/bin/sh
TomcatID=$(ps -ef |grep tomcat |grep -w ‘tomcat‘|grep -v ‘grep‘|awk ‘{print $2}‘)
StartTomcat=tomcat_startup_path
WebUrl=www.xxx.com #需测试服务
TomcatMonitorLog=monitor_log_path
Monitor()
{
if [ $TomcatID ]; then
TomcatServiceCode=$(curl -I -m 10 -o /dev/null -s -w %{http_code} $WebUrl)
if [ $TomcatServiceCode -eq 200 ]; then
echo "tomcat is running......"
else
echo "restart,TomcatID--->>$TomcatID"
kill -9 $TomcatID
echo "kill -9 tomcat ok"
sleep 3
echo "sleep 3 ok, starting Tomcat ..."
$StartTomcat
echo "send sms ..."
curl -d "params" "sms_server_url"
fi
else
echo "tomcat process is no exsit, tomcat restart..."
$StartTomcat
curl -d "params" "sms_server_url"
echo "------------tomcat start success-------------" fi } Monitor>>$TomcatMonitorLog
赋予脚本执行权限 chmod +x xxx.sh chmod 777 xxx.sh
加入定时任务
crontab -e
*/1 * * * * shell_path 每分钟执行
以上是关于shell脚本监控Tomcat并重启发送短信的主要内容,如果未能解决你的问题,请参考以下文章
shell通过shell编写ping包及arp的监控并发送短信