Okay, first post! So I have this situation where I need to check for a process older than 5 minutes by a particular process name. The problem is that the system in question is a customized version of CentOS 4, so it has pmisc 21.4 and killall didn't incorporate -o/--older-than until 22.9. I have no option of upgrading the system whatsoever, so please don't suggest that as an option. It's an internal system without outside facing access, so the potential security issues are not a big concern for this customer.
Engineers are working on a solution to figure out why this process is occasionally getting hung up, but in the mean time, I just need to cron a script to check for the process to kill it off if it's been running for more than 5 min, because it should normally only take 30-45 seconds to complete.
I'm pretty sure this can be accomplished with ps output, some egrep and regex syntax, but I don't know how to put it together.
The process is called "synch". Someone gave me the following suggested code, but it seems to not work correctly.
#!/bin/bash for i in $(pgrep -f synch) do TIME=$(ps --no-headers -o etime $i | cut -d":" -f 2) if [ "$TIME" -gt 4 ] ; then kill $i fi done