Tailing last modified part of log file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Tailing last modified part of log file
# 1  
Old 03-04-2010
Tailing last modified part of log file

I have a log file which contains data like this
Quote:
Starting to get delta file 3/1/2010 7:0:0
1111111.log exist
12356656.log exist

Starting to get delta file 3/1/2010 18:0:0
767895.log exist
4445654.log exist
677989888988.log exist

Starting to get delta file 3/2/2010 7:0:0
989876.log exist
667677.log exist

Starting to get delta file 3/2/2010 18:0:0
1982028.log exist
555656.log exist
7777788.log exist


Starting to get delta file 3/3/2010 7:0:0
5555521.log exist
345745.log exist

Starting to get delta file 3/3/2010 18:0:0
1982028.log exist
234454.log exist
123.log exist
666666.log exist
234355.log exist
566556.log exist
4456778565.log exist
2345454.log exist
This log file is updated twice a day at 7am and 6pm,
I want a script(which i will make run at 7:10am and 6:10pm) which should fetch only the last appended lines since last update..

I mean.. if i execute the script at 7.10am 3/3/2010
it should fetch only
5555521.log exist
345745.log exist

and if i execute the script at 6:10pm 3/3/2010
it should fetch only
1982028.log exist
234454.log exist
123.log exist
666666.log exist
234355.log exist
566556.log exist
4456778565.log exist
2345454.log exist

How can i achieve this.. obviously i cannot user "Tail" command since i don't know how much lines of output it's gonna give..

Please let me know how can i achieve this???
Any help is highly appreciated !! thank You
# 2  
Old 03-04-2010
of course you can.
wc before, count the lines, or characters

tail -c
tail -num

read man tail
man wc
# 3  
Old 03-04-2010
Code:
gawk 'BEGIN{RS="";FS="\n";now=systime()}
      {split($1,a,"[ /:]")};
      {t=mktime(a[8]" "a[6]" "a[7]" "a[9]" "a[10]" "a[11])};
      {if ((now-t)<1000) print $0}' urfile

1000 is second, means to get the logs which was generated less than 1000s, you can ajust it for your request.
# 4  
Old 03-04-2010
You can get the date and time variables then extract what you want using sed
Code:
var_time=$(date '+%m/%d/20%y %k')
 sed -n "/^Starting.*$var_time/,/^$/p" file

# 5  
Old 03-04-2010
Quote:
Originally Posted by ldapswandog
You can get the date and time variables then extract what you want using sed
Code:
var_time=$(date '+%m/%d/20%y %k')
 sed -n "/^Starting.*$var_time/,/^$/p" file

Smilie
var_time=$(date '+%m/%d/%Y %k')
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to make a loop to read the input from a file part by part?

Hi All, We've a VDI infrastructure in AWS (AWS workspaces) and we're planning to automate the process of provisioning workspaces. Instead of going to GUI console, and launching workspaces by selecting individual users is little time consuming. Thus, I want to create them in bunches from AWS CLI... (6 Replies)
Discussion started by: arun_adm
6 Replies

2. Shell Programming and Scripting

Tailing logs from different files into one single file

Hi Please help me in finding a solution for tailing multiple log files and writing all of them into one common file. I have 4 log files with same name in 4 different folders. Whenever I post a Request - any one of these 4 log files gets updated with some log detail in the below format : ... (5 Replies)
Discussion started by: nisav
5 Replies

3. AIX

Syslog log file permission not getting modified.

I'm trying to set the permission for the syslog log file in syslog,conf. --------- The below is my configuration file ## example: # "mail messages, at debug or higher, go to Log file. File must exist." # "all facilities, at debug and higher, go to console" # "all facilities, at crit or... (1 Reply)
Discussion started by: novaothers
1 Replies

4. Shell Programming and Scripting

Getting the date part from the log file.

Hi, I have a script that runs to generate a log file which is in this format: Start: Friday, April 29, 2011 18:30 User : Host : Database : I need to write a script that reads this log file (RUN.LOG) and rename the existing log file... (7 Replies)
Discussion started by: ashok@119
7 Replies

5. UNIX for Dummies Questions & Answers

tailing a file which contains Control chracters

Hi. I have a log file which gets updated by a java process and it uses ASCII STX and ETX characters (i.e CTRL-B and CTRL-C characters) to demarcate each XML message logged. so the format of the file is something like STX XML_MESSAGE1 .. .. ETX STX XML_MESSAGE2 .. .. ETX each XML... (4 Replies)
Discussion started by: gregoryp
4 Replies

6. Shell Programming and Scripting

Get a part of a String from a log file

Hey there, I'm searched for one day your forum for a similar solution. Didn't find one, sorry :( Now here is what I'm searching for. I have the following multiple lines from a log (Edit: log name is SystemOut.log - this is not my day. I Apologize): 000042e2 1_BLA_Yab I logging.LogInfo... (5 Replies)
Discussion started by: nobodyhere
5 Replies

7. Shell Programming and Scripting

Tailing new log file & echo the string on console

Guys, I do have a script that runs to take the server out from network, after running the script it is writing the new log file{outFile} in to directory . Now what i need is my script should tail the last modified file{outFile} & search the string {Server Status} ans should echo the same at the... (0 Replies)
Discussion started by: raghunsi
0 Replies

8. Shell Programming and Scripting

Tailing 2 or more log files simultaneously PERL

Hi, I am having issue where I have to tail 3 log files continuously (forever) and while I am reading the files , parse them and shove the data into DB. I can do this with one file totally fine but how can I read 3 files at the same time? I am not really looking for code (but would be nice) but... (3 Replies)
Discussion started by: Dabheeruz
3 Replies

9. Shell Programming and Scripting

How to extract certain part of log file?

Hi there, I'm having some problem with UNIX scripting (ksh), perhaps somebody can help me out? For example: ------------ Sample content of my log file (text file): -------------------------------------- File1: .... info_1 ... info_2 ... info_3 ... File2: .... info_1 ... info_2 ...... (10 Replies)
Discussion started by: superHonda123
10 Replies

10. UNIX for Dummies Questions & Answers

how to retrieve original contents of a modified file (modified using vi)

Made changes to a file using vi editor and saved those changes now realised that the changes are not required How can I get the previous version of the file.i.e the one which was there on which I had made changes (3 Replies)
Discussion started by: novice100
3 Replies
Login or Register to Ask a Question