Go Back   HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials > Linux Forums > Programming/Scripts

Do you like HowtoForge? Please consider supporting us by becoming a subscriber.
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 14th February 2013, 07:41
bejaia bejaia is offline
Junior Member
 
Join Date: Feb 2013
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Capture a log portion closest of 2 hours

Hello,

./my_script.sh works without brackets.
I want to modify ./my_script.sh when in the server.log the date and hour are between brackets like that [24/01/2013 09:10]
I tried in vain certains modifications.
Can you help me ? Thank you for your help.


Code:
cat server.log
Code:
error jonas
aaaaaaaaaaaaaa
bbbbbbbbbbbbb
cccccccccccc
24/01/2013 09:10 sssssssss
sssssssssssssss
cccccccccccccc
nnnnnnnnnnnnn
24/01/2013 10:10 uuuuuuuuu
uuuuuuuuuuuuuuu
jjjjjjjjjjjjjj
ttttttttttttttt
mmmmmmmmmmmmm
24/01/2013 10:30 oooooooooo
oooooooooooo
sssssssssssss
qqqqqqqqqqq
24/01/2013 10:45 vvvvvvvvv
vvvvvvvvv
sssssssss
wwwwwwwwww
my_script.sh

Code:
file=$1
if [ -f $file.gz ]
     then command="gunzip -c"
     else command=cat
fi
$command $file | awk -F"[/ ]" -v S="24/01/2013 10:10" -v E="24/01/2013 10:30" '
function dcmp(b) {
  if($3>b[3])return  1;
  if($3<b[3])return -1;
  if($2>b[2])return  1;
  if($2<b[2])return -1;
  if($1>b[1])return  1;
  if($1<b[1])return -1;
  if($4>b[4])return  1;
  if($4<b[4])return -1;
  return 0;
}
BEGIN{split(S, ds, "[/ ]"); split(E, de, "[/ ]") }
/^[0-9][0-9]\/[0-1][0-9]\/[0-9][0-9][0-9][0-9] / {
   if(s&&dcmp(de)>=0) {print; exit}
   if(!s&&dcmp(ds)<=0) {f=x;w=1}
   if(!s&&dcmp(ds)>=0) {printf "%s",f; f=x; s=1 }
}
!w&&!s {f=f $0 "\n"}
s'
Reply With Quote
Sponsored Links
 

Bookmarks

Thread Tools
Display Modes

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

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
SMTP error Dovecot postfix aberrio Server Operation 26 3rd February 2011 15:25
MyDNS Segfaults crypted General 19 22nd July 2010 23:49
FTP Problems wabz Installation/Configuration 6 11th January 2010 19:51
Unable to receve email aberrio Server Operation 16 8th July 2009 11:26
slow download through webserver problem snewp Technical 14 9th May 2008 06:25


All times are GMT +2. The time now is 09:14.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.