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 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.....
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
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.
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.
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??
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...
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
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...
./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
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
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;
@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
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.