How to process only new line of tail -f command from live log file?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to process only new line of tail -f command from live log file?
# 1  
Old 10-17-2013
Linux How to process only new line of tail -f command from live log file?

Hi,

I want to read a live log file line by line and considering those line which are newly added to file
Below code I am using, which read line but as soon as it read new line from log file its starts processing from very first line of file.

Code:
tail -F /logs/COMMON-ERROR.log | while read myline; do
ERROR_CODE=$(echo $ myline | awk -F ' ' '{for (i=1;i<=NF;i++){if($i ~ "^[1-1]" && length($i)==6){print $i}}}')
ERROR_CODE_DET=$(echo $ myline | awk -F ' ' '{print $1" "$2}')
echo "$ERROR_CODE_DET" "$ERROR_CODE"

if [ "$ERROR_CODE" -eq 100021 ] ; then
ERROR_MSG="Route failed. Moving to failed routes pool."
fi
done


Last edited by vbe; 10-17-2013 at 10:50 AM.. Reason: code tags + rm fancy fonts...
# 2  
Old 10-17-2013
Try tail -n0 -F /logs/COMMON-ERROR.log |....
# 3  
Old 10-17-2013
This thread may also help
# 4  
Old 10-17-2013
Quote:
Originally Posted by CarloM
Try tail -n0 -F /logs/COMMON-ERROR.log |....
tail -n0 -F giving same output after reciving new file in log file .....Smilie
# 5  
Old 10-17-2013
Does it work with --follow=name rather than -F?
# 6  
Old 10-17-2013
Could it be the upper case F? from man tail:
Quote:
-f, --follow[={name|descriptor}]
output appended data as the file grows; -f, --follow, and --follow=descriptor are equivalent

-F same as --follow=name --retry

.
.
.
--retry
keep trying to open a file even when it is or becomes inaccessible; useful when following by name, i.e., with --follow=name
May be lower case f does not reopen the file?
# 7  
Old 10-17-2013
My suspicion was that the implied --retry is the problem.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Homework & Coursework Questions

How to display certain line of file only using head or tail in 1 command?

First month learning about the Linux terminal and it has been a challenge yet fun so far. We're learning by using a gameshell. I'm trying to display a certain line ( only allowed 1 command ) from a file only using the head or tail. I'm pretty about this answer: head -23 history.txt | tail -1... (1 Reply)
Discussion started by: forzatekk
1 Replies

2. UNIX for Advanced & Expert Users

Alternative to tail -n -0 -F for monitoring live log file

Hello, I have been working on script which need to generate an alert based upon live logs. If string is found then an alert mail must triggered. tail -n -0 -F works fine to redirect the each latest line from live logs file to grep a pattern for matching but it seems to be not working on... (7 Replies)
Discussion started by: ketanraut
7 Replies

3. Shell Programming and Scripting

Linux backup command line or live cd?, what do you use?

Linux backup command line or live CD?, what do you use? (4 Replies)
Discussion started by: kaja
4 Replies

4. Shell Programming and Scripting

Reading line by line from live log file using while loop and considering only those lines start from

Hi, I want to read a live log file line by line and considering those line which start from time stamp; Below code I am using, which read line but throws an exception when comparing line that does not contain error code tail -F /logs/COMMON-ERROR.log | while read myline; do... (2 Replies)
Discussion started by: ketanraut
2 Replies

5. Shell Programming and Scripting

How to use command tail -f & show line number.

Hello Guys, I have created function which is as follow: tail -f filename |grep "Key word" output from this command 19-11-2011 21:09:15,234 - INFO Numbement - error number:result = :11 19-11-2011 21:09:15,286 - INFO Numbement - error number:result = :11 19-11-2011 21:09:15,523 - INFO... (5 Replies)
Discussion started by: ooilinlove
5 Replies

6. Shell Programming and Scripting

How to process log file line by line?

Greetings, I'm new to this forum, also new to shell script I have done some simple shell script before, like backup linux machine using rsync and crontab, but now I need to do some log analyzing, which is beyond my ability... so I'm going to seek for help in this forum, hope someone could give... (5 Replies)
Discussion started by: lunaticdawn
5 Replies

7. Shell Programming and Scripting

Display Specific line number using tail command

Hi , 1)i want to display specific line number using tail command. e.g. display 10 line from end. Please help... 2)Want to display line 10 to 15 (from end)using tail command) (2 Replies)
Discussion started by: vivek1489
2 Replies

8. Shell Programming and Scripting

How to perform action on newest line in log using tail?

I don't quite know what I'm doing, so this simple script is proving a challenge. Here is some pseudo code that doesn't work yet: if tail -1 "WORKING.txt" >/dev/null | egrep "^NMBR=*" > /dev/null then curl -k 'http://www.myserver.com/log.cgi?input=$?' echo "hi there" fi Purpose:... (3 Replies)
Discussion started by: dihewidd
3 Replies

9. Shell Programming and Scripting

Tail 86000 lines from 1.2 million line file?

I have a log file that is about 1.2 million lines long and about 300MB. we need a way to clean up this file and only keep the last few thousand lines. if i use tail command we run our of memory as the file is too big. I do have a key word to match on. example, we want to keep every line... (8 Replies)
Discussion started by: robsonde
8 Replies

10. Solaris

Tail command in one line

HI i have to copy the last 5000 lines form a log file and copy the same in the same file .overwriting the same log file. ex: tail -5000 testfile1 > testfile2 cat testfile2 mv tesftfile2 testfile1 will produce the correct result.but i want to have this done in one line???? (4 Replies)
Discussion started by: saurabh84g
4 Replies
Login or Register to Ask a Question