指令碼內容:java_check.sh
#! /bin/bash # if [ -z `pidof java` ]; then echo -e `date +%Y-%m-%d` `date +%R`. “33[31m33[1m(JAVA)Process does not exist! 33[0m” >> /data/logs/java_check.log /usr/local/tomcat/bin/startup.sh >/dev/null 2>&1 sleep 30 netstat -tnlp >> /data/logs/java_check.log echo -e “r” >> /data/logs/java_check.log fi
計劃任務,十五分鐘執行一次
複製代碼 代碼如下:
*/15 * * * * root /usr/local/bin/java_check.sh
一個監控java程式啟動並執行shell
#!/bin/shexport J_LIB=/data/sms/lib;export CLASSPATH=.:$J_LIB/jtds-1.2.jar:$J_LIB/log4j-1.2.12.jar:$J_LIB/postgresql-8.1-404.jdbc3.jar;export JAVA_HOME=/usr/java/jdk1.5.0_05export JRE=/usr/local/jdk/jreexport SHELL=/bin/bashexport HOME=/data/sms#java check statusif /bin/ps ax | /bin/grep -v grep | /bin/grep "java XinTai"; then cd;else cd /data/sms/xintai; /usr/java/jdk1.5.0_05/bin/java XinTai >/dev/null &fi
定時執行可以保證 java XinTai可以一直在運行