ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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
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
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
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
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:
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
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...
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.
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.)
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.