SHELL脚本监控JAVA进程的代码
程序员文章站
2022-04-25 15:31:59
脚本内容:java_check.sh
#! /bin/bash
#
if [ -z `pidof java` ]; then
echo -e...
脚本内容: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/sh export 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_05 export jre=/usr/local/jdk/jre export shell=/bin/bash export home=/data/sms #java check status if /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可以一直在运行