LinuxQuestions.org
Help answer threads with 0 replies.
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, 11:30 AM   #16
nomiezvr4
LQ Newbie
 
Registered: Jan 2011
Posts: 26

Original Poster
Rep: Reputation: 0

Hey Markush I'm actually looking for it in minutes

here is what I have so far:

echo "at going into ggsci"
./ggsci << endit >$AUDIT_DIR/check_oracle_output_$ORACLE_SID.txt


info all
endit

cd /usr/users/audit
target='! ! ! ! 00:30:00'
{ echo; echo "$target"; more 'check_oracle_output_$ORACLE_SID.txt';}| sort -t' ' -k5,5 -s | sed '1,/! ! ! !/d'



if [ $? -eq 0 ]
then
echo "one than 30 minutes" > $AUDIT_DIR/notify_gg.txt
retstatus=101
fi

will the above work?

If possible and a preferred method...
I could also use the grep command if that will work for anything over 30 minutes..I believe right the code is for 30secs.....
 
Old 08-11-2011, 11:31 AM   #17
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
Quote:
Originally Posted by markush View Post
Code:
grep -e "[3-9][[:digit:]]$\|[1-9]:[[:digit:]][[:digit:]]$"
This probably works for the specific case of 00:30:00, but you couldn't use that style for times that take up more than one field, e.g. 01:23:45, which would require an entirely different solution if the need were to arise in the future.
Kevin Barry
 
Old 08-11-2011, 11:44 AM   #18
nomiezvr4
LQ Newbie
 
Registered: Jan 2011
Posts: 26

Original Poster
Rep: Reputation: 0
Kevin i do appreciate all your help:
I believe I am almost there

I'm on SUNOS 5.10 Generic_144488-06 sun4u sparc SUNW,Sun-Fire-V890

I am getting this error:
grep: illegal option -- q
$AUD_DIR/check_oracle_output_$ORACLE_SID.txt: No such file or directory
Usage: grep -hblcnsviw pattern file . . .
pscdcdb01:/usr/users/oracle/sql>sort: illegal option -- s
usage: sort [-cmu] [-o output] [-T directory] [-S mem] [-z recsz]
[-dfiMnr] [-b] [-t char] [-k keydef] [+pos1 [-pos2]] files...


what i have is
Code:
echo "at going into ggsci"
./ggsci << endit >$AUDIT_DIR/check_oracle_output_$ORACLE_SID.txt


info all
endit

cd /usr/users/audit
target='! ! ! ! 00:30:00'
{ echo; echo "$target"; more '$AUD_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
All the above is oneline where it should be.. i put an extra line inbetween -t' and ' -k5 because it was coming out funny

Last edited by nomiezvr4; 08-11-2011 at 11:48 AM.
 
Old 08-11-2011, 12:01 PM   #19
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
The -q option must not be present in your version grep. You can use grep . > /dev/null instead; -q merely suppresses output.

-t' ' specifies a single space as the value passed to the -t option; the 's quote it. This specifies a space as the field separator for sort.
Kevin Barry

PS For some reason I forgot to insert LC_ALL=C immediately before sort. You should add that to make sure this still works even if the locale is changed on the system, i.e. change sort -t' ' -k5,5 -s to LC_ALL=C sort -t' ' -k5,5 -s.

Last edited by ta0kira; 08-11-2011 at 12:07 PM.
 
Old 08-11-2011, 12:17 PM   #20
markush
Senior Member
 
Registered: Apr 2007
Location: Germany
Distribution: Slackware
Posts: 3,979

Rep: Reputation: Disabled
Well, I didn't get that the last column are the seconds, but this
Code:
grep -e "[3-9][[:digit:]]:[[:digit:]][[:digit:]]$\|[1-9]:[[:digit:]][[:digit:]]:[[:digit:]][[:digit:]]$"
will work
with this input
Code:
EMMP 00:00:00 00:06:00
EMMP 00:00:00 00:29:00
EMMP 00:00:00 00:31:00
PMMP 00:00:00 01:09:00
RMDRA 00:00:00 00:00:00
RMDRB 00:00:00 01:06:00
RMDRB 00:00:00 00:38:00
RMDRB 00:00:00 01:23:45
I've to this output
Code:
EMMP 00:00:00 00:31:00
PMMP 00:00:00 01:09:00
RMDRB 00:00:00 01:06:00
RMDRB 00:00:00 00:38:00
RMDRB 00:00:00 01:23:45
My code checks if there is at least a "30" in the minutes-columnt and if this is not the case it checks if there is at least a "01" int the hour-column.

Markus
 
Old 08-11-2011, 07:47 PM   #21
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,005

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Have we all perhaps missed the bigger picture here? After re-reading the entire thread and paying more attention
to the OPs replies, it appears that if any of the lines are greater than 30 minutes he only requires a single entry placed in the file??

Is this correct?
 
Old 08-11-2011, 08:42 PM   #22
nomiezvr4
LQ Newbie
 
Registered: Jan 2011
Posts: 26

Original Poster
Rep: Reputation: 0
Hey guys, thanks for your all replies...I believe that MARKUSH code will be ideal, once i put that into my shell and if its successful.

GRAIL you are correct.
Let me give a better explanation, so the program i use basically updates these times every second and sometimes when there is an error, the time will increase. I will have this run in crontab and it will send me an e-mail.

What I wanted to do was, is grep the file for any time bigger than 30min's.
Then i was going to do was
if [ $? -eq 1 ]
then echo "time has passed 30minutes"; (also at this point it will send me an e-mail, will edit that at a later point)
fi


From what I can tell MARKUSH code will grep for anything that is higher than 30 or 01 hour, which is perfectly fine with me. My threshold was 30minutes but if its easier for it to be at 01hour, that is fine with me. If the grep works like that, then its perfect. Therefore my if statement will work correctly.

As for as kevins code(which I greatly appreciate his help), im having a hard time on this system, i believe we have korn(if that matters)


What I wanted to do was
but what I was going to do was
here is exactly what i have
Code:
echo "at going into ggsci"
./ggsci << endit >$AUDIT_DIR/check_oracle_output_$ORACLE_SID.txt


info all
endit

echo "starting target"

target='! ! ! ! 00:00:30'
{ echo; echo "$target"; cat '$AUDIT_DIR/check_oracle_output_$ORACLE_SID.txt';}| sort -t' ' -k5,5 -s | sed '1,/! ! ! !/d' | grep
> dev/null 
echo "time is greater than 30" > $AUDIT_DIR/file1.txt
I get error

./test2gg.ksh
at going into ggsci
starting target
./test2gg.ksh[45]: dev/null: cannot create
cat: cannot open $AUDIT_DIR/check_oracle_output_$ORACLE_SID.txt
pscdcdb01:/usr/users/oracle/sql>sort: illegal option -- s
usage: sort [-cmu] [-o output] [-T directory] [-S mem] [-z recsz]
[-dfiMnr] [-b] [-t char] [-k keydef] [+pos1 [-pos2]] files...

Last edited by nomiezvr4; 08-11-2011 at 09:06 PM.
 
Old 08-11-2011, 08:58 PM   #23
nomiezvr4
LQ Newbie
 
Registered: Jan 2011
Posts: 26

Original Poster
Rep: Reputation: 0
quick update...

tried MARKUSH
This is what I have done to check
T.1
file containts:
MANAGER RUNNING
EXTRACT EMMP 00:00:00 00:00:03
EXTRACT PMMP 00:00:00 00:00:08
REPLICA RMDRA 00:08:00 00:00:03
REPLICAT RMDRB 00:00:00 00:00:08

when i do
Code:
grep -e "[3-9][[:digit:]]:[[:digit:]][[:digit:]]$\|[1-9]:[[:digit:]][[:digit:]]:[[:digit:]][[:digit:]]$" check_oracle_output_$ORACLE_SID.txt
I got error: grep: illegal option -- e
Usage: grep -hblcnsviw pattern file . . .

so i did
Code:
egrep -e "[3-9][[:digit:]]:[[:digit:]][[:digit:]]$\|[1-9]:[[:digit:]][[:digit:]]:[[:digit:]][[:digit:]]$" check_oracle_output_$ORACLE_SID.txt
which look like it worked then i did an
echo $? and got return 1

T.2
file containts:
MANAGER RUNNING
EXTRACT EMMP 00:30:00 00:00:03
EXTRACT PMMP 01:00:00 00:00:08
REPLICA RMDRA 00:38:00 00:00:03
REPLICAT RMDRB 00:00:00 00:00:08


Code:
egrep -e "[3-9][[:digit:]]:[[:digit:]][[:digit:]]$\|[1-9]:[[:digit:]][[:digit:]]:[[:digit:]][[:digit:]]$" check_oracle_output_$ORACLE_SID.txt
echo $? is still 1

Just for more info the whole file check_oracle_output_$ORACLE_SID.txt containts this :more check1_oracle_output_mdrpq1q1.txt

GoldenGate Command Interpreter for Oracle
Version 10.4.0.0 Build 014
Solaris, sparc, 64bit (optimized), Oracle 10 on Jul 6 2009 21:44:59

Copyright (C) GoldenGate Software, Inc. 1995-2009.
The GoldenGate software may include other code written by third parties;
details regarding such third party code, including applicable copyright,
legal and licensing notices are available at http://support.goldengate.com.



GGSCI (pscdcdb01) 1>
GGSCI (pscdcdb01) 1>
GGSCI (pscdcdb01) 1>
Program Status Group Lag Time Since Chkpt

MANAGER RUNNING
EXTRACT EMMP 00:00:00 00:00:03
EXTRACT PMMP 00:00:00 00:00:08
REPLICAT RMDRA 00:08:00 00:00:03
REPLICAT RMDRB 00:00:00 00:00:08


GGSCI (pscdcdb01) 2>


I hope im doing it right..Also trying to give as much info as possible

Last edited by nomiezvr4; 08-11-2011 at 09:07 PM.
 
Old 08-11-2011, 09:40 PM   #24
nomiezvr4
LQ Newbie
 
Registered: Jan 2011
Posts: 26

Original Poster
Rep: Reputation: 0
Guys, I feel like I'm making this too complicated, well atleast for me it is.
would it be easier if i just do anything that is at an hour or greater?
I would like to just grep for anything that is at one hour, what I mean is
(since my crontab entry will run every 15minutes, I know it will catch it)
01:00:00 or greater
01:01:00
01:21:00
SO basically it would catch both the middle ones from below:
EXTRACT EMMP 00:30:00 00:00:03
EXTRACT PMMP 01:08:00 00:00:08
REPLICA RMDRA 01:48:00 00:00:03
REPLICAT RMDRB 00:00:00 00:00:08

just look for 01: aspect...i'm sure you get the point.
I'm thinking just grep the 01 from the time...

will that make things easier?
 
Old 08-11-2011, 10:52 PM   #25
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
./test2gg.ksh
at going into ggsci
starting target
./test2gg.ksh[45]: dev/null: cannot create
cat: cannot open $AUDIT_DIR/check_oracle_output_$ORACLE_SID.txt
pscdcdb01:/usr/users/oracle/sql>sort: illegal option -- s
usage: sort [-cmu] [-o output] [-T directory] [-S mem] [-z recsz]
[-dfiMnr] [-b] [-t char] [-k keydef] [+pos1 [-pos2]] files...
What I wrote is meant for sh or bash. Sorry, I should have said that. I don't think that's the problem, though. The "dev/null" error is because it needs to be "/dev/null". It also looks like your version of sort doesn't have -s, but I think it can be left out. There are a few other things that got missed during transposition, also.
Quote:
Originally Posted by nomiezvr4 View Post
Guys, I feel like I'm making this too complicated, well atleast for me it is.
would it be easier if i just do anything that is at an hour or greater?
If that works for you it could be done as markush suggested with a few modifications. Remember that that's string matching, so what makes it easier is the fact that your time specification has only one non-zero digit. My solution is also entirely text-based but it takes advantage of 0-9 being ordered as such in ASCII. In either case you're merely simulating numerical operations without actually using numbers.
Kevin Barry

Last edited by ta0kira; 08-11-2011 at 10:53 PM.
 
Old 08-12-2011, 12:45 AM   #26
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,005

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
As grep seems a little under whelming on SOLARIS, maybe this basic awk may help:
Code:
echo "at going into ggsci"
./ggsci << endit >$AUDIT_DIR/check_oracle_output_$ORACLE_SID.txt


info all
endit

echo "starting target"

awk 'split($NF, a, ":") == 3 && $(NF-1) ~ /:/ && 3600*a[1] + 60*a[2] + a[3] > 1800{print time is greater than 30";exit}' "$AUDIT_DIR/check_oracle_output_$ORACLE_SID.txt" > "$AUDIT_DIR/file1.txt"
 
Old 08-12-2011, 01:02 AM   #27
markush
Senior Member
 
Registered: Apr 2007
Location: Germany
Distribution: Slackware
Posts: 3,979

Rep: Reputation: Disabled
Hello,

I thought about a solution with Perl. When Larry Wall wrote Perl he had such situations in mind. Perl was originally designed to extract reports out of logfiles.

The advantage is that it is easier to understand than a long line with patterns for grep.

Here the Perl-code
Code:
#!/usr/bin/perl

use strict;
use warnings;

open (FILE, "logfile.txt") or die "cannot open file: $!\n";

while (<FILE>) {
    if (m/[A-Z]+\s+[A-Z]*\s*\d\d:\d\d:\d\d\s+(\d\d):(\d\d):(\d\d)$/) {
        my ($hours, $minutes, $seconds) = ($1, $2, $3);
        print if ($minutes >= 30 || $hours >= 1);
    }
}
close FILE;
it assumes that the filename is "logfile.txt".

Markus

Last edited by markush; 08-12-2011 at 06:05 AM.
 
Old 08-12-2011, 06:57 AM   #28
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,005

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
@markush - nice work, but I think we also have to consider the seconds in the case that hour is 0, minute is 30 but if seconds greater than 0 then it should be included? I am sure this is trivial to add to your solution
 
Old 08-12-2011, 07:11 AM   #29
markush
Senior Member
 
Registered: Apr 2007
Location: Germany
Distribution: Slackware
Posts: 3,979

Rep: Reputation: Disabled
Hello grail,
Quote:
Originally Posted by grail View Post
@markush - nice work,
you're welcome
Quote:
but I think we also have to consider the seconds in the case that hour is 0, minute is 30 but if seconds greater than 0 then it should be included?
isn't it?
My code checks for $minutes >= 30 and if we have at least 30 minutes independent of the seconds the line is printed. If $minutes < 30 (e.g. 29) $seconds can't be bigger than 59, and therefore everything between 29:00 and 29:59 doesn't match.

Or did you mean something different?

Markus
 
Old 08-12-2011, 09:10 AM   #30
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,005

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Hey Markus

Good points. I was thinking that 30 was ok but not more. I am sure 1 second won't break the bank
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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:37 AM.

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