Liunx 重启 定时 重启 tomcat 实现 代码

  

1.restart.sh

#! /Bin /sh

. /etc /profile

echo > > restartTomcat.logecho > > restartTomcat.logecho " ============================================= ======== " > > restartTomcat.logecho " ===== [`date + '% y-% m-% d% H:% M:% S'`] iniciar Tarea ====== " > > restartTomcat.logecho " ============================================= ======== " > > restartTomcat.log

# 查看 tomcat5 是否 有 进程 pid = `ps aux |  grep tomcat5 |  grep -v grep |  grep -v retomcat |  awk '{print $ 2}' `

echo " AA: el id de proceso = $ pid " > > restartTomcat.log

if [-n " $ pid " ]entonces . /usr/java/retomcat.shelseecho " AA: [`date + '% y-% m-% d% H:% M:% S'`] [WARN] tomcat not start, startup tomcat " > > restartTomcat.log /usr /java /tomcat5 /bin /startup.sh > > restartTomcat.logfi

2.retomcat.sh #! /bin /shecho " AA: [`fecha + '% y-% m-% d% H:% M:% S'`] tomcat es Inicio, se apagará Tomcat " > > restartTomcat.log # 关闭 tomcat5 /usr/java/tomcat5/bin/shutdown.sh > > restartTomcat.logsleep 10spid = `ps aux |  grep tomcat5 |  grep -v grep |  grep -v retomcat |  awk '{print $ 2}' `# 查看 是否 关闭 mientras que [-n " $ pid " ]; doecho " AA: [`date + '% y-% m-% d% H:% M:% S'`] fail shutdown tomcat id = $ pid " > > restartTomcat.logecho " AA: [`date + '% y-% m-% d% H:% M:% S'`] kill tomcat id = $ pid " > > restartTomcat.logkill -9 $ pidsleep 1mpid = `ps aux |  grep tomcat5 |  grep -v grep |  grep -v retomcat |  awk '{print $ 2}' `hecho # 关闭 成功 , 重启 echo " AA: [` date + '% y-% m-% d% H:% M:% S'`] exitoso apagado tomcat " > > restartTomcat.logsleep 3mecho " AA: [`date + '% y-% m-% d% H:% M:% S'`] start startup tomcat " > > restartTomcat.log /usr /java /tomcat5 /bin /startup.sh > > restartTomcat.log

3. 在 添加 定时 任务

#crontab -e

0 5 * * * /usr/java/bak/restartTomcat.sh 表示 5 点执行 定时 任务

4. 赋于 执行 的 权限

#chmod + x /usr/java/restart.sh

#chmod + x /usr /java /retomcat .sh


en"],null,[0.90109104],en"]]]

Copyright © Conocimiento de Windows All Rights Reserved