![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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 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. |
|
||||
|
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 |
|
||||
|
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
|
|
||||
|
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
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|