#!/bin/bash step=2 for((i=0;i<60;i=i+step));do ps aux|grep apptomcat |grep -v grep >/dev/null y=`echo $?` if [ "$y" -ne "0" ];then ps aux|grep webtomc ...
#!/bin/bash step=2 for((i=0;i<60;i=i+step));do ps aux|grep apptomcat |grep -v grep >/dev/null y=`echo $?` if [ "$y" -ne "0" ];then ps aux|grep webtomcat |grep -v grep >/dev/null if [ `echo $?` -eq "0" ];then ps uax|grep webtomcat|grep -v grep |awk '{ print $2}'|xargs kill -9 &>/dev/null else exit fi else sleep 2 continue fi exit done 添加到crontab中 [root@web2 bin]# cat /var/spool/cron/root
* * * * * /data/2.sh
實時監控apptomcat,如果apptomcat掛了,則把webtomcat也殺死