标签:highlight tcl out export start option java 时间 主题
主题 通过监控tomcat状态 如果找不到tomcat进程就进行启动
如果tomcat进程存在 就输出时间 进程号
注意在tomcat的bin目录下 需要新增 java_home jre_home的变量
[root@duanxin bin]# cat setclasspath.sh #!/bin/sh # ----------------------------------------------------------------------------- # Set CLASSPATH and Java options # # $Id: setclasspath.sh 345508 2005-11-18 15:54:56Z yoavs $ # ----------------------------------------------------------------------------- # First clear out the user classpath export JAVA_HOME=/usr/local/jdk export JRE_HOME=/usr/local/jdk/jre
如果不进行修改就会出现以下报错
[info]/usr/local/tomcat7/apache-tomcat-7.0.88/bin/startup.sh,请稍候......
Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
At least one of these environment variable is needed to run this program
脚本如下
[root@duanxin bin]# cat /nod/jian.sh #!/bin/sh TomcatID=$(ps -ef |grep tomcat |grep -v ‘grep‘|grep -v ‘tomcat.log‘|awk ‘{print $2}‘) # tomcat启动程序(这里注意tomcat实际安装的路径) StartTomcat=/usr/local/tomcat/bin/startup.sh Monitor() { echo "[info][$(date +‘%F %H:%M:%S‘)]tomcat情况" if [[ $TomcatID ]];then # 这里判断TOMCAT进程是否存在 echo "[info]当前tomcat进程ID为:$TomcatID..." else echo "[error]tomcat进程不存在!tomcat开始自动重启..." echo "[info]$StartTomcat,请稍候......" sh $StartTomcat fi echo "------------------------------" } Monitor>>/nod/tomcat.log
定时任务部分
*/1 * * * * /nod/jian.sh
输出日志
标签:highlight tcl out export start option java 时间 主题
原文地址:https://www.cnblogs.com/nodchen/p/11613170.html