The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
data extract from dates Krrishv Shell Programming and Scripting 5 06-05-2009 12:33 AM
Need script to generate all the dates in DDMMYY format between 2 dates frozensmilz Shell Programming and Scripting 2 01-29-2009 06:06 AM
Time Between Dates Sreejith_VK HP-UX 2 02-27-2008 02:02 AM
UNIX Dates ndoggy020 UNIX for Dummies Questions & Answers 9 02-14-2008 06:25 PM
comparing 2 dates k_oops9 Shell Programming and Scripting 7 11-15-2004 02:07 AM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-02-2009
koma koma is offline
Registered User
  
 

Join Date: Jul 2009
Posts: 3
Extract loglines between two dates

Hi all,
this is my first post, and i want to say hello to everyone in there.

I've a little problem for you all .
I have a log like this:
Code:
38714 07/02/09 00:01:36  nsrd web2consolidato:D:\ done saving to pool 'SISTMSW0060' (Q09480) 32 GB
38752 07/02/09 00:01:37  nsrd /dev/rmt/STK0.2.10.5 11:Verify label operation in progress
38752 07/02/09 00:01:39  nsrd /dev/rmt/STK0.2.10.5 11:Mount operation in progress
42504 07/02/09 00:01:48  nsrd media event cleared: Waiting for 1 writable volumes to backup pool 'index' tape(s) or disk(s) on
 bolgt03
38718 07/02/09 00:01:48  nsrd bolgt03:index:serceias6bo009 saving to pool 'index' (Q12581)
38718 07/02/09 00:01:48  nsrd bolgt03:index:efbpmb04 saving to pool 'index' (Q12581)
38718 07/02/09 00:01:48  nsrd bolgt03:index:bostn03qd saving to pool 'index' (Q12581)
38718 07/02/09 00:01:48  nsrd bolgt03:index:efbpme06 saving to pool 'index' (Q12581)
0 07/02/09 00:01:51  nsrmmdbd              pools supported: index, SISTMSW0060;
12361 07/02/09 00:01:52  nsrd [Jukebox `CRMF01', operation # 1967]. Finished with status: succeeded
42506 07/02/09 00:01:58  nsrd write completion notice: Writing to volume Q32308 complete
42506 07/02/09 00:02:08  nsrd write completion notice: Writing to volume Q09480 complete
9935 07/02/09 00:02:10  nsrmmdbd Save set ssid:3343637708 cloneid:1246485675 retention time update is before browse time, adju
sting browse time
and i need a script to extract the lines created in the last hour.
Example
I run the script at 15:31 - 07/01/09
i need every line created between the 14:31 - 07/01/09 and now.
But is not certain that there is a line in the log with that hour. The log can be unchanged in the last week or can contain several lines with the same timestamp.
The script need also to run between days and mounth changes example:
run at 00:30 07/01/09 i need every line FROM 23:30 an 06/30/09 .

Please help me... my head is near to explode.
  #2 (permalink)  
Old 07-02-2009
rakeshawasthi rakeshawasthi is offline
Registered User
  
 

Join Date: Aug 2004
Location: India
Posts: 379
Welcome to unix.com and Please dont explode.
search with datecalc and you will get a script that can do the date calculation for you.
use the date command to get the date when you are running the script.
Try 'man date'
use awk to extract the datestamp from the logfile. use datecalc to check the difference between current date and logfile date.
~ Cheers
  #3 (permalink)  
Old 07-02-2009
koma koma is offline
Registered User
  
 

Join Date: Jul 2009
Posts: 3
is not that simple if the date does not appear in the file because in that minute/hour doesn't log ?

---------- Post updated at 06:16 AM ---------- Previous update was at 05:43 AM ----------

Done
Code:
#!/usr/local/bin/bash
export PATH="$PATH:/usr/local/coreutils/bin"
#07/02/09 12:35:57
ADESSO=$(cdate "+%m/%d/%y %H:%M")
UNORAFA=$(cdate -d "1 hour ago" "+%m/%d/%y %H:%M")
UNORAFA_S=$(cdate -d "1 hour ago" +%s)
echo $ADESSO
echo $UNORAFA
echo $UNORAFA_S
A="0"
while [ "$A" -lt "61" ] ; do
        echo $A
        QUACK=$(grep -n "$UNORAFA" daemon.log|tail -1)
        if [ "$QUACK" = "" ]; then
                let A=$A+1
                let UNORAFA_S=$UNORAFA_S+60
                UNORAFA=$(cdate -d "@$UNORAFA_S" "+%m/%d/%y %H:%M")
                echo devo provare $UNORAFA
        else
                echo TROVATO $UNORAFA
                echo $QUACK
                TOTAIL=$(echo $QUACK |awk -F\: '{print $1}')
                NUMLINES=$(wc -l daemon.log|awk '{print $1}')
                echo $TOTAIL
                echo $NUMLINES
                let TOTAIL=$NUMLINES-$TOTAIL
                tail -$TOTAIL daemon.log > ESTRATTO.txt
                A=61
        fi
done
  #4 (permalink)  
Old 07-02-2009
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,531
Quote:
Originally Posted by koma View Post
Please help me... my head is near to explode.
See here for an example using GNU awk.

Last edited by ghostdog74; 07-02-2009 at 07:51 AM..
  #5 (permalink)  
Old 07-02-2009
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,122
Quote:
Originally Posted by ghostdog74 View Post
See here for an example.
it's gawk specific - not that's bad or anything...
  #6 (permalink)  
Old 07-02-2009
koma koma is offline
Registered User
  
 

Join Date: Jul 2009
Posts: 3
awk: Function systime is not defined.
The source line number is 4.
:|
Mhh

Code:
      A. V. Aho, B. W. Kernighan, P. J. Weinberger: The AWK Programming
      Language, Addison-Wesley, 1988.

 STANDARDS CONFORMANCE
      awk: SVID2, SVID3, XPG2, XPG3, XPG4, POSIX.2

 Hewlett-Packard Company            - 9 -      HP-UX 11i Version 1: Mar 2007
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 01:50 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0