"if" for time


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users "if" for time
# 1  
Old 02-05-2004
"if" for time

I am trying to filter some output with an "if" in an "awk" command but I cant seem to find the right syntax for time.


Command:
ps -ef -o comm -o time

Output:
/usr/../../ddterm 0:40
/bin/csh 11:30
/user/../../graph 30:00
....... ......

I want to pull the processes that have been running for more than 12 hours.

ps -ef -o comm -o time | awk '{if ($2 -gt 12) print}'

Any help would be greatly appreciated.

And yes, I did utilize the search function.

Last edited by viRaven; 02-05-2004 at 03:56 PM..
# 2  
Old 02-05-2004
Selecting PS Entries by Time Elapsed

Quote:
Originally posted by viRaven
And yes, I did utilize the search function.
Smilie

You didn't say what shell, but here's how I'd do it in ksh:

ps -ef -o comm= -o time= | awk -F: '$2 > 12 {print}'
# 3  
Old 02-05-2004
Thanks for such a quick reply.

Any shell is fine by me.

Heres the problem though, that will filter by the minutes.

So it will not display:

a process with the time 18:16:(10 <----not greater than 12)

-o time option displays time as [[dd-]hh::]mm:ss

So..a Process running for 13 days-10 hours looks like this:
13-10:57:33

So I need to evaluate it as a whole, or the hour column along with the day column.

-----
part of the post was displaying as a smily...

Last edited by oombera; 02-05-2004 at 04:47 PM..
# 4  
Old 02-05-2004
Oops. Yeah, I was running PS on our system and nothing came up as running over 24 hours, so I forgot a 1- or 2-, etc will show up...
# 5  
Old 02-05-2004
Let's try this convoluted looking line instead: Smilie

ps -ef -o comm= -o time= | awk '/[0-9]-[0-9][0-9]:[0-9][0-9]:[0-9][0-9]/ || substr($2,1,2) > 12 {print $0}'

This way, if either the process is running a day or more (and something like 1- or 2- is present) or the hour section of the running time is greater than 12, then the line prints.
# 6  
Old 02-06-2004
substr

I took the first part of the awk command and used that. Changing the 12 hour criteria to anything over a day.

But I'd like to figure this out, I've been trying for the last few hours, but my scripting, programming is not up to snuff.

taking the input of:

command1 38:41
command2 0:07
command3 3-11:37:51
command4 1:45
command5 1-04:00:50


the:

substr($2,1,2) > 12

will print commands 1,3,4

That substr will evaluate the first two digits is comes across totally disregarding the special characters ":" and "-"

so command4 1:45 = true because 14 > 12
command5 1-04:00:50 = false because 1-0 < 12 though this is more than 12 hours, which I want.

Do you think it would be possible to format this with the awk version of split?
# 7  
Old 02-06-2004
I made that script on the assumption that if something's been running 1 minute and 45 seconds, it'd show up as 00:01:45 (as it does on my system) and not 1:45 (as you have it).

It gets even more convoluted... this displays any entry that shows a day (blue part) OR shows an hour greater than or equal to 12 (red part).

ps -ef -o comm= -o time= | awk '/[1-9]-[0-9][0-9]:[0-9][0-9]:[0-9][0-9]/ || /[1-2][2-9]:[0-9][0-9]:[0-9][0-9]/ || /[2][0-9]:[0-9][0-9]:[0-9][0-9]/ {print $0}'
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. AIX

Apache 2.4 directory cannot display "Last modified" "Size" "Description"

Hi 2 all, i have had AIX 7.2 :/# /usr/IBMAHS/bin/apachectl -v Server version: Apache/2.4.12 (Unix) Server built: May 25 2015 04:58:27 :/#:/# /usr/IBMAHS/bin/apachectl -M Loaded Modules: core_module (static) so_module (static) http_module (static) mpm_worker_module (static) ... (3 Replies)
Discussion started by: penchev
3 Replies

2. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

3. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

4. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

5. Shell Programming and Scripting

How to remove "New line characters" and "spaces" at a time

Dear friends, following is the output of a script from which I want to remove spaces and new-line characters. Example:- Line1 abcdefghijklmnopqrstuvwxyz Line2 mnopqrstuvwxyzabcdefghijkl Line3 opqrstuvwxyzabcdefdefg Here in above example, at every starting line there is a “tab” &... (4 Replies)
Discussion started by: anushree.a
4 Replies

6. UNIX for Advanced & Expert Users

add seconds to: date"|"time"|"HHMMSS

Hey all, I have a shell that invokes a AWK. In this AWK i want invoke a function that receives 3 parameters: date: 20080831 time: 235901 duration: 00023 that function receive this 3 parameters and sum to this value two more seconds: 2008083123590100025 Remember that in case that... (3 Replies)
Discussion started by: anaconga
3 Replies

7. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies
Login or Register to Ask a Question