制作定时任务,监控Tomcat是否处于启动如果不是启动状态,运行脚本启动tomcat。

 
  
编写脚本脚本名称为crontab.sh
TomcatID=$(ps -ef | grep /usr/local/oms/oms_console |grep -v grep |awk '{print $2}')
if test -n "$TomcatID"
then
echo "oms_console already running!"
exit 0
fi
su - -c "/usr/local/oms/oms_console/bin/startup.sh &"
sleep 3
TomcatID=$(ps -ef | grep /usr/local/oms/oms_console |grep -v grep |awk '{print $2}')
if test -n "$TomcatID"
then
echo "oms_console restore succeed"
exit 0
else
echo "oms_console start error!"
exit 1
fi

脚本编写成功后创建定时任务,输入crontab -e
在其中添加*/2 * * * * /bin/sh /opt/crontab/crontab.sh

你可能感兴趣的:(linux,脚本,tomcat)