How to read log files from last read


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to read log files from last read
# 1  
Old 02-13-2012
How to read log files from last read

Hi
i am looking a way to look at a log file(log.txt) from the last time I've read it.
However after some days the main log file(log.txt) is rename to (log.txt.1).
So now i will have two log files as below.

log.txt.1
log.txt

Now, i have to read the log from the point where i have left the last read.
I can do this by storing the last line no# read in seperate file and and start reading the log file from that line, however if the log files is renamed(backed up), this logic will not work.

Any suggesstion.

Last edited by sumitsks; 02-13-2012 at 06:06 AM..
# 2  
Old 02-13-2012
Is there a time stamp in the log entries?
# 3  
Old 02-13-2012
Yes, it has the timestamp in the below format.

2012-02-12 07:01:04 some string....
# 4  
Old 02-13-2012
Then surely the correct approach would be to remember the last read time stamp, grep for it, open that file ...
This User Gave Thanks to Skrynesaver For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Read latest log files and perform database insert

Hi Experts, I have a situation where I need to write a shell script to continuously monitor a log directory with multiple log files and perform following: 1. Read the latest log file continuously and grep "Success" OR "Failure" 2. As it capture either Success or Failure, it has to perform a... (1 Reply)
Discussion started by: rish_max
1 Replies

2. UNIX for Dummies Questions & Answers

Read in Multiple log files and output selected variables and values to cvs file

I have several problems with my problems: I hope you can help me. 1) the If else statement I am getting an error message. My syntax must be incorrect because the entire statement is throwing an error. For example in filew.log if these items don't exist Memsize, SASFoundation and also if... (0 Replies)
Discussion started by: dellanicholson
0 Replies

3. Shell Programming and Scripting

[Bash] Read History function & Read Arrowkeys

Hi. How can I create a history function? (By "read" command or so) & How can I configure a read command so that the arrow keys are not displayed so funny? (^[[A) Thanks in advance. (4 Replies)
Discussion started by: sinnlosername
4 Replies

4. UNIX for Dummies Questions & Answers

How to read and understand Sendmail 8.14 log files ?

Can some one please help me know how exactly to understand logs in sendmail 8.14.5. I am pretty new to sendmail. I am running rhel6 on my system and i installed sendmail on it. Its just a test enivornment and i am sending and receiving emails on my localshot only. Jun 13 18:32:38 serv1... (0 Replies)
Discussion started by: Rohit Bhanot
0 Replies

5. UNIX for Dummies Questions & Answers

When reading a csv file, counter to read 20 lines and wait for minute then read next 20 till end

Hello All, i am a newbie and need some help when reading a csv file in a bourne shell script. I want to read 10 lines, then wait for a minute and then do a reading of another 10 lines and so on in the same way. I want to do this till the end of file. Any inputs are appreciated ... (3 Replies)
Discussion started by: victor.s
3 Replies

6. Shell Programming and Scripting

Read Embedded Newline characters with read (builtin) in KSH93

Hi Guys, Happy New Year to you all! I have a requirement to read an embedded new-line using KSH's read builtin. Here is what I am trying to do: run_sql "select guestid, address, email from guest" | while read id addr email do ## Biz logic goes here done I can take care of any... (6 Replies)
Discussion started by: a_programmer
6 Replies

7. UNIX for Advanced & Expert Users

read() wont allow me to read files larger than 2 gig (on a 64bit)

Hi the following c-code utilizing the 'read()' man 2 read method cant read in files larger that 2gig. Hi I've found a strange problem on ubuntu64bit, that limits the data you are allowed to allocate on a 64bit platform using the c function 'read()' The following program wont allow to allocate... (14 Replies)
Discussion started by: monkeyking
14 Replies

8. Shell Programming and Scripting

Read multiple log files and create output file and put the result

OS : Linux 2.6.9-67 - Red Hat Enterprise Linux ES release 4 Looking for a script that reads the following log files that gets generated everynight between 2 - 5am Master_App_20090717.log Master_App1_20090717.log Master_App2_20090717.log Master_App3_20090717.log... (2 Replies)
Discussion started by: aavam
2 Replies

9. Shell Programming and Scripting

Shell script to read multiple log files

Hi all, I have to generate some report from shell script .We have stacktrace log file which generate hourly basis. So now my q is that how this shell script will read all stacktrace log file for particlular day and parse accordingly desire output. Any help or suggestion as i am newbie with... (1 Reply)
Discussion started by: esungoe
1 Replies
Login or Register to Ask a Question