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.
Reply
 
Thread Tools Display Modes
  #1  
Old 14th February 2013, 06: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
Reply

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 14:25
MyDNS Segfaults crypted General 19 22nd July 2010 22:49
FTP Problems wabz Installation/Configuration 6 11th January 2010 18:51
Unable to receve email aberrio Server Operation 16 8th July 2009 10:26
slow download through webserver problem snewp Technical 14 9th May 2008 05:25


All times are GMT +2. The time now is 06:03.


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