I want to put in crontab a shell script that will monitor the java process and if it's the memory is more than 80% then I want to restart it.
can any one help?
Thanks!!
Elad.
Linux script – find java process and restart it if it is more than 80% Mem High
bashcentosjavalinuxscripting
Best Answer
Perfect use case for monit. http://mmonit.com/
Example Config
check process foo with pidfile "/var/run/foo"
cat /var/run/foo.pidstart program = "/bin/foo -c foo.conf"
stop program = "/bin/kill -KILL
"
if totalmem is greater than X.0 MB for 5 cycles then restart
The reason you want monit rather than a script is that it can email you, provide logs, and honestly a lot more, but I'll leave the research up to you.