Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

script to check for old java processes

Status
Not open for further replies.

mmcds

MIS
Jul 5, 2007
28
US
I am running on SuSE Linux and I am trying to find a way how I can find any process that is older than 1 day/24 hours and kill it via a script that I will put in cron to run once a day or so. These are WebSphere/Java processes the get hung from time to time due to programming issues or whatever the case may be. Any suggestions would be greatly appreciated.
 
If you look at the output from ps -ef you'll see that older processes have their timestamp in the format 'Mon dd', eg 'Nov 12' whereas the newer processes have their timestamp in the format 'hh:mm', eg 16:03.

So you want an awk statement which will filter out all the java processes which have their timestamp in the format [A-Z][a-z][a-z][0-9][0-9] - somthing like
Code:
ps -ef | awk '$5 ~ /[A-Z][a-z][a-z][0-9][0-9]/ && /java/ {print}'
Once you are convinced that the expression will ONLY return old processes then you can refine it to print only the PID
Code:
ps -ef | awk '$5 ~ /[A-Z][a-z][a-z][0-9][0-9]/ && /java/ {print $2}'
and, as long as you're convinced that works, pipe it into xargs with
Code:
ps -ef | awk '$5 ~ /[A-Z][a-z][a-z][0-9][0-9]/ && /java/ {print $2}'| xargs kill
Remember, test, test, and test again!

Ceci n'est pas une signature
Columb Healy
 
Thanks for the suggestions. That worked great.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top