I am trying to find the running time of a process on a linux server. I using etime
to achieve this. Here's the code i am using
ps -eo etime,args | grep "process"|awk '{print $1}'
The sample output for this
28-08:42:13
I am then doing the following to convert this to seconds and sending myself a mail when the runtime is less that 30 mins(1800 secs)
ps -eo etime,args | grep "process"|awk '{print $1}'|awk -F'[-: ]+' '/:/ {t=$2+60*$1; print t}'
The problem i am seeing is, when converting to seconds, it's taking the $2(secs) and $1(mins) from the running time and sending me a mail even though the process has been up for 28-08:42:13
.
Is there a better way of doing the conversion of runtime to secs? Using $3 and $4 from the first output doesn't work for cases where the runtime is less than 1 hour. It's picking a garbage value and returning a different value than the actual running time.
Please help.