Process running more than require time

Frineds I need assistance in writing a script . Newbie to scripting.

How to find list of processes that are running more than an hour . Below i used the step to get the etime and stime . Now by getting the result i need to display longer time process with full listing.

ps -aef -o user,pid,etime,stime,args |grep <process name> | awk '{print $3}'

which gives the below result

42:03
3-06:21:33
01:08:05
18:23
00:00
01:07:55
59:06
58:13

Thank you in advance

Why not do print $2,3 to get both fields?

I did that but my result should show only the PID's which are taking longer time.

And you need the PID too, not just the time...

awk '{ split($3,A,":"); T=(A[1]*60)+A[2]; $0=$2" "$3 } T>60'

Note that using -f and -o together is not portable. On many systems that will give you a full listing with the additional fields specified by -o appended to the end the line of normal -f output. If you just want the fields you specified listed for any process that has been running for an hour or more, try:

ps -ae -o user,pid,etime,stime,args | awk 'split($3,f,/[-:]/)>2'

Or use:

ps -eo user,pid,etime,stime,args | awk '{n=split($3,A,":");$0=$2" "$3}n>=3'

Yoda Thank you for your reply but I get an error saying


bash-2.05$ ps -eo user,pid,etime,stime,args | awk '{ split($3,A,":"); T=(A[1]*60)+A[2]; $0=$2" "$3 } T>60'
awk: can't set $0
 record number 1

---------- Post updated at 09:26 AM ---------- Previous update was at 09:24 AM ----------

Don Cragun Thank you for your reply but when i use your command i get an error

bash-2.05$ ps -ae -o user,pid,etime,stime,args | awk 'split($3,f,/[-:]/)>2'
awk: syntax error near line 1
awk: bailing out near line 1

---------- Post updated at 09:28 AM ---------- Previous update was at 09:26 AM ----------

Corona688 thank you for your response. I get an error below.

bash-2.05$ ps -ae -o user,pid,etime,stime,args | awk '{ split($3,A,":"); T=(A[1]*60)+A[2]; $0=$2" "$3 } T>60'
awk: can't set $0
 record number 1

Please use nawk instead of awk if you are on SunOS or Solaris.

awk on SunOS or Solaris is broken.

Thank you Yoda It really helps... You are the best :slight_smile:

---------- Post updated at 11:00 AM ---------- Previous update was at 10:38 AM ----------

Yoda

It works but still it gives me the processes that runs lesser than one hour....I want to get only the process that runs more than an hour

23708 4-00:36:41
2082 17:59
27344 15-05:12:40
895 9-21:59:01
9305 9-21:52:10
16975 28-02:42:54
2001 18:00

Since you're running on a Solaris system, please try this again using /usr/xpg4/bin/awk or nawk instead of awk .

Thanks Don . Your idea worked for me after using nawk.

---------- Post updated at 01:35 PM ---------- Previous update was at 01:34 PM ----------

Yoda ....your script also worked for me without any issue.....thank you for timely assitance...