Skip to main content
added 57 characters in body
Source Link
Rahul Patil
  • 25.6k
  • 26
  • 85
  • 96

You can use following function to Get Process elapse time in minutes

GetProcTime() { local p=$1 ps -eao "%C %U %c %t" | awk "/$p/"'{print $4}' | awk -F":" '{{a=$1*60} {b=a+$2}; if ( NF != 2 ) print b ; else print $1 }' } 

Test

root@ubuntu:/tmp# GetProcTime monit 0310 root@ubuntu:/tmp# if [[ $(GetProcTime apache2 104 104 104 104 104monit) -ge 360 ]]; then echo "Process is running more than 6 hrs"; else echo "OK"; fi 104OK root@ubuntu:/tmp# GetProcTime init 460466 root@ubuntu:/tmp# uptime if 15:34:56[[ up$(GetProcTime init) 7:40,-ge 360 1]]; user,then echo load"Process average:is 0.00,running 0.01,more 0.05 root@ubuntu:/tmp#than echo6 $((hrs"; 460else /echo 60"OK"; ))fi 7Process is running more than 6 hrs 

You can use following function to Get Process elapse time in minutes

GetProcTime() { local p=$1 ps -eao "%C %U %c %t" | awk "/$p/"'{print $4}' | awk -F":" '{{a=$1*60} {b=a+$2}; if ( NF != 2 ) print b ; else print $1 }' } 

Test

root@ubuntu:/tmp# GetProcTime monit 03 root@ubuntu:/tmp# GetProcTime apache2 104 104 104 104 104 104 root@ubuntu:/tmp# GetProcTime init 460 root@ubuntu:/tmp# uptime  15:34:56 up 7:40, 1 user, load average: 0.00, 0.01, 0.05 root@ubuntu:/tmp# echo $(( 460 / 60 )) 7 

You can use following function to Get Process elapse time in minutes

GetProcTime() { local p=$1 ps -eao "%C %U %c %t" | awk "/$p/"'{print $4}' | awk -F":" '{{a=$1*60} {b=a+$2}; if ( NF != 2 ) print b ; else print $1 }' } 

Test

root@ubuntu:/tmp# GetProcTime monit 10 root@ubuntu:/tmp# if [[ $(GetProcTime monit) -ge 360 ]]; then echo "Process is running more than 6 hrs"; else echo "OK"; fi OK root@ubuntu:/tmp# GetProcTime init 466 root@ubuntu:/tmp# if [[ $(GetProcTime init) -ge 360 ]]; then echo "Process is running more than 6 hrs"; else echo "OK"; fi Process is running more than 6 hrs 
Source Link
Rahul Patil
  • 25.6k
  • 26
  • 85
  • 96

You can use following function to Get Process elapse time in minutes

GetProcTime() { local p=$1 ps -eao "%C %U %c %t" | awk "/$p/"'{print $4}' | awk -F":" '{{a=$1*60} {b=a+$2}; if ( NF != 2 ) print b ; else print $1 }' } 

Test

root@ubuntu:/tmp# GetProcTime monit 03 root@ubuntu:/tmp# GetProcTime apache2 104 104 104 104 104 104 root@ubuntu:/tmp# GetProcTime init 460 root@ubuntu:/tmp# uptime 15:34:56 up 7:40, 1 user, load average: 0.00, 0.01, 0.05 root@ubuntu:/tmp# echo $(( 460 / 60 )) 7