LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-11-2011, 09:39 AM   #1
nomiezvr4
LQ Newbie
 
Registered: Jan 2011
Posts: 26

Rep: Reputation: 0
grep greater than time period??


Hey guys, I'm fairly new at unix shell scripting and I have a quick question.
Quick overview I devolped a script where I generate a file ..and I want to grep any time greater than 30 minutes.
For example i run this which generates a file

./ggsci << endit >$AUDIT_DIR/check_output.out


The file contains:

EMMP 00:00:00 00:00:06
PMMP 00:00:00 00:01:09
RMDRA 00:00:00 00:00:00
RMDRB 00:00:00 00:01:06

I want to grep for any time greater than 30minutes..
How can I do that?

Last edited by nomiezvr4; 08-11-2011 at 09:41 AM.
 
Old 08-11-2011, 09:51 AM   #2
nomiezvr4
LQ Newbie
 
Registered: Jan 2011
Posts: 26

Original Poster
Rep: Reputation: 0
to give a better idea

Program Status Grp lag TimeChkpt

MANAGER

RUNNG
EXTRACT RUN EMMP 00:00:00 00:00:06
EXTRACT RUN PMMP 00:00:00 00:00:06
REPLICAT RUN RMDRA 00:00:00 00:00:00
REPLICAT RUN RMDRB 00:00:00 00:00:06


One column is lag, the other is time check point. If there is a lag and how big of a lag and check point time also...sometimes their is an error and the lag or check point is greater than 30minutes ..

Hope that helps

My thought process is that for a word its something like
grep -w 'Agent is Running and Ready' $AUDIT_DIR/check_2.out

so for time I want it to grep a time greater than 30mintes...
 
Old 08-11-2011, 09:51 AM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192
Please explain further, you mean the difference between column 2 and 3 is greater than 30 or the difference between values in a column with relation to the following or preceding line?
 
Old 08-11-2011, 10:02 AM   #4
nomiezvr4
LQ Newbie
 
Registered: Jan 2011
Posts: 26

Original Poster
Rep: Reputation: 0
what these numbers do is let us know if there is any sort of lag and how much lag. If there is a lag the numbers in column two will increase, if the system has not check pointed for a time frame the numbers in column 3 will increase.

usually the numbers will stay below 5 minutes and if the system is running real slow they might get to 20 minutes.

What i do is runa command to generates the below and puts it into a file:
I run
./ggsci << endit >$AUDIT_DIR/check_oracle_output_$ORACLE_SID.out

the file check_oracle_output_$ORACLE_SID.out contains info below


Program Status Grp lag TimeChkpt

MANAGER

EXTRACT RUN EMMP 00:00:00 00:00:06
EXTRACT RUN PMMP 00:00:00 00:00:06
REPLICAT RUN RMDRA 00:00:00 00:00:00
REPLICAT RUN RMDRB 00:00:00 00:00:06


What I wanted to do was grep the file for anytime greater than 00:30:00 and then i was going to set up an if clause and send myself an e-mail..
hope that helps
 
Old 08-11-2011, 10:21 AM   #5
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
Instead of grep you might do this:
Code:
target='! ! ! ! 00:00:30'
{ echo; echo "$target"; cat 'the-file.txt'; } | sort -t' ' -k5,5 -s | sed '1,/! ! ! !/d'
Basically $target is the max elapse with "!" as a place-holder for the first 4 fields. sort as called above will sort by the 5th field, then sed will delete all lines that come at or before $target. Incidentally, the output will be sorted by the 5th field. The extra echo is so sed works correctly if there isn't anything before $target.
Kevin Barry
 
Old 08-11-2011, 10:28 AM   #6
nomiezvr4
LQ Newbie
 
Registered: Jan 2011
Posts: 26

Original Poster
Rep: Reputation: 0
Barry thanks for the info. Now this is to check for anything above 30 correct, not just 30 itself?

also for the way it would be is...
your code (target='! ! ! ! 00:00:30'{ echo; echo "$target"; cat 'the-file.txt'; } | sort -t' ' -k5,5 -s | sed '1,/! ! ! !/d') then file name check_oracle_output_$ORACLE_SID.out


like
target='! ! ! ! 00:00:30'{ echo; echo "$target"; cat 'the-file.txt'; } | sort -t' ' -k5,5 -s | sed '1,/! ! ! !/d' check_oracle_output_$ORACLE_SID.out



bare with me, im still a bit new
 
Old 08-11-2011, 10:30 AM   #7
nomiezvr4
LQ Newbie
 
Registered: Jan 2011
Posts: 26

Original Poster
Rep: Reputation: 0
sorry feel like an idiot, just saw the-file.txt part
 
Old 08-11-2011, 10:33 AM   #8
nomiezvr4
LQ Newbie
 
Registered: Jan 2011
Posts: 26

Original Poster
Rep: Reputation: 0
Is the code for anything above 30 or just at 30?

I have this
target='! ! ! ! 00:00:30'{ echo; echo "$target"; cat '$AUDIT_DIR/check_oracle_output_$ORACLE_SID.out';} | sort -t' ' -k5,5 -s | sed '
1,/! ! ! !/d'


and i am getting an error on: ./testgg.ksh[31]: syntax error at line 42 : `}' unexpected

Last edited by nomiezvr4; 08-11-2011 at 10:35 AM.
 
Old 08-11-2011, 10:37 AM   #9
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
Sorry, it needs to be two separate lines. Either that or insert ";" where the newline is. I've used "the-file.txt" in place of the input file and output is to standard output. This should give you everything 30s or greater. If you need the lines in their original order I can help with that, also.
Kevin Barry
 
Old 08-11-2011, 10:40 AM   #10
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192
Wouldn't that be 30 seconds in the format it is in now? If the lost column is HH:MM:SS (is this correct) are we simply looking for any last column greater than 00:30:00?
If so, how about:
Code:
awk -F: '/RUN/ && ($(NF-2) > 0 || $(NF - 1) > 30)' check_oracle_output_$ORACLE_SID.out
Or if you really want to, skip the output file and just pipe your command into the front.
 
Old 08-11-2011, 10:46 AM   #11
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
Quote:
Originally Posted by grail View Post
Wouldn't that be 30 seconds in the format it is in now? If the lost column is HH:MM:SS (is this correct) are we simply looking for any last column greater than 00:30:00?
I was trying to provide a solution that allowed for arbitrary times, e.g. 01:23:45.
Kevin Barry
 
Old 08-11-2011, 10:48 AM   #12
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192
Quote:
I was trying to provide a solution that allowed for arbitrary times, e.g. 01:23:45
As am I
 
Old 08-11-2011, 11:03 AM   #13
nomiezvr4
LQ Newbie
 
Registered: Jan 2011
Posts: 26

Original Poster
Rep: Reputation: 0
I am looking for it minutes but i could tell that kevin had it in seconds
Now what im trying to do is basically see if the return status for the above is 0
if it is 0 then echo "time is greater than 30" > $AUDIT_DIR/file1.txt


so in other words could i do
target='! ! ! ! 00:30:00'
{ echo; echo "$target"; cat '$AUDIT_DIR/check_oracle_output_$ORACLE_SID.txt';}| sort -t' ' -k5,5 -s | sed '1,/! ! ! !/d'

if [ $? -eq 0 ]
then
echo "time is greater than 30" > $AUDIT_DIR/file1.txt
fi

So if the target command does succeeds with something above 30 then the text time is greater than 30 would be inputted into the file1.txt...

Am I correct?

Last edited by nomiezvr4; 08-11-2011 at 11:15 AM.
 
Old 08-11-2011, 11:20 AM   #14
markush
Senior Member
 
Registered: Apr 2007
Location: Germany
Distribution: Slackware
Posts: 3,979

Rep: Reputation: Disabled
Hi,

I've found this with grep only
Code:
grep -e "[3-9][[:digit:]]$\|[1-9]:[[:digit:]][[:digit:]]$"
for me it works, with this file
Code:
EMMP 00:00:00 00:00:06
PMMP 00:00:00 00:01:09
RMDRA 00:00:00 00:00:00
RMDRB 00:00:00 00:01:06
RMDRB 00:00:00 00:00:38
I got this output
Code:
PMMP 00:00:00 00:01:09
RMDRB 00:00:00 00:01:06
RMDRB 00:00:00 00:00:38
which as I understood is what you expected.

Markus

Last edited by markush; 08-11-2011 at 11:22 AM.
 
Old 08-11-2011, 11:28 AM   #15
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
Quote:
Originally Posted by nomiezvr4 View Post
I am looking for it minutes but i could tell that kevin had it in seconds
Now what im trying to do is basically see if the return status for the above is 0
if it is 0 then echo "time is greater than 30" > $AUDIT_DIR/file1.txt


so in other words could i do
target='! ! ! ! 00:30:00'
{ echo; echo "$target"; cat '$AUDIT_DIR/check_oracle_output_$ORACLE_SID.txt';}| sort -t' ' -k5,5 -s | sed '1,/! ! ! !/d'

if [ $? -eq 0 ]
then
echo "time is greater than 30" > $AUDIT_DIR/file1.txt
fi

So if the target command does succeeds with something above 30 then the text time is greater than 30 would be inputted into the file1.txt...

Am I correct?
You would need to explicitly check for lines being output from sed. You also don't need the if statement.
Code:
target='! ! ! ! 00:30:00'
{ echo; echo "$target"; cat '$AUDIT_DIR/check_oracle_output_$ORACLE_SID.txt'; } | \
   sort -t' ' -k5,5 -s | sed '1,/! ! ! !/d' | grep -q . && \
   echo "time is greater than 30" > $AUDIT_DIR/file1.txt
Also, please use [CODE][/CODE] tags for your code or the # button.
Kevin Barry

PS Note that I've used "!" as a placeholder because it has the lowest ASCII of printing characters besides " ", which makes it come out on top of the other lines with a non-empty respective field (for future reference.)

Last edited by ta0kira; 08-11-2011 at 11:34 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Calculate Time Period in Scripting anishkumarv Linux - Newbie 10 03-17-2011 08:56 AM
How to search date period in access log using grep bilalcochin Linux - Newbie 2 02-19-2010 08:24 AM
[SOLVED] idle time greater than uptime mcguire Linux - Newbie 2 10-22-2009 01:08 PM
grep does not care about file names beginning with period. stf92 Linux - Newbie 15 06-04-2009 07:27 PM
FC5 slows down after period of time asidarin Linux - Server 19 06-25-2007 10:46 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:04 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration