SHELL脚本监控JAVA进程的代码
脚本内容:java_check.sh
#!/bin/bash # if[-z`pidofjava`];then echo-e`date+%Y-%m-%d``date+%R`.“33[31m33[1m(JAVA)Processdoesnotexist!33[0m”>>/data/logs/java_check.log /usr/local/tomcat/bin/startup.sh>/dev/null2>&1 sleep30 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/sh exportJ_LIB=/data/sms/lib; exportCLASSPATH=.:$J_LIB/jtds-1.2.jar:$J_LIB/log4j-1.2.12.jar:$J_LIB/postgresql-8.1-404.jdbc3.jar; exportJAVA_HOME=/usr/java/jdk1.5.0_05 exportJRE=/usr/local/jdk/jre exportSHELL=/bin/bash exportHOME=/data/sms #javacheckstatus if/bin/psax|/bin/grep-vgrep|/bin/grep"javaXinTai";then cd; else cd/data/sms/xintai; /usr/java/jdk1.5.0_05/bin/javaXinTai>/dev/null& fi
定时执行可以保证javaXinTai可以一直在运行