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? |
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... |
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?
|
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 |
Instead of grep you might do this:
Code:
target='! ! ! ! 00:00:30' Kevin Barry |
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 |
sorry feel like an idiot, just saw the-file.txt part
|
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 |
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 |
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 |
Quote:
Kevin Barry |
Quote:
|
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? |
Hi,
I've found this with grep only Code:
grep -e "[3-9][[:digit:]]$\|[1-9]:[[:digit:]][[:digit:]]$" Code:
EMMP 00:00:00 00:00:06 Code:
PMMP 00:00:00 00:01:09 Markus |
Quote:
Code:
target='! ! ! ! 00:30:00' 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.) |
All times are GMT -5. The time now is 05:43 PM. |