Demand:
Monitoring Top life Today, Tomcat process%CPU time accounted for more than 80% times to kill the process, and then restart the pair should be Tomcat, and record the reboot of the Tomcat, as well as the restart time of the log
#!/bin/bash# Print tomcatid number #tomcatid= ' Ps-ef |grep tomcat|grep-w ' tomcat ' |grep-v Grep|awk ' {print $ {} ' tomcatid= ' JPS |grep Bootstrap|awk ' {print '} ' datetime= ' (date ' +%f%h:%m:%s ') ' #获取单前时间LOG =/tmp/tomcat.log #日志文件if [!-N ' $ Tomcatid "];then echo" please start Tomcat. "#判断pid是否为空else for i in $tomcatid;d o tomcatdir= ' ps aux|grep $i | awk ' {for (i=1;i<nf;i++) if ($i ~/dcatalina\.home/) Print $i} ' |awk-f ' = ' {print $} ' |head-1 ' #获取tomcat的catalina home Path if ["$i"];then echo "The Tomcat is starting. PID: $i. Tomcatdir: $tomcatdir "#通过pid判断tomcat是否启动; started judging cpu cpu= ' top-bn1 |grep" $i "| awk ' {print $9} ' |cut-d '."-f1 " c8/>if [$cpu-lt];then kill-9 "$i" sleep 3 "$tomcatdir/bin/startup.sh" echo "the Tomcat Pid: $i Restart Tomcat time $DATETIME ">> $LOG fi fi donefi~
This article is from the "Time Still Wipe" blog, please be sure to keep this source http://xulianglinux.blog.51cto.com/8001428/1775388
Monitor CPU usage for multi-instance Tomcat