Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Enterprise Linux Forums > Linux - Enterprise
User Name
Linux - Enterprise This forum is for all items relating to using Linux in the Enterprise.


  Search this Thread
Old 10-31-2012, 10:25 AM   #1
Registered: Oct 2005
Location: Tierra Firma, Earth
Distribution: Debian of course...
Posts: 196

Rep: Reputation: 30
Problem running tail -f against oft-truncated file

howdy folks,

I want to monitor a log file for a specific event and grab an iostat the moment the event is detected. The bash function below works fine until the file gets renamed (logfile.nnn.txt), gzipped (logfile.nnn.txt.gz), moved (mv logfile.nnn.txt.gz ./backup_logs) and re-created (touch logfile.txt). Once it's truncated it ceases to work.

tail -f logfile.txt | while read INFILE
[[ "${INFILE}" == *"event_12345"* ]]
&& iostat -t >> iostat_when_process_times_out.txt
&& beep

Need solution so that I can still monitor the log for the event and capture an iostats when it happens. Any help would be greatly appreciated. Thanks.
Old 10-31-2012, 12:15 PM   #2
Registered: Oct 2005
Location: Tierra Firma, Earth
Distribution: Debian of course...
Posts: 196

Original Poster
Rep: Reputation: 30
Hey I think I fixed it.

I did two things:
1. created a symbolic link to the logfile
2. Instead of running "tail -f" I tried with "tail -F" (capital F) which looks like it includes a retry function. The function spit out this message:
tail: `tempsymboliclink_logfile' has been replaced; following end of new file

And I'm sitting pretty with an iostats log. My guess is it's the tail option, not the symbolic link that mattered but it's working as-intended.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] ar: .libs/libbfd.a: Error reading archive.o: File truncated grail Programming 4 06-01-2010 06:28 PM
[SOLVED] redirecting output, observe with tail -f <file>, while running, without screen? srons Linux - Newbie 3 04-22-2010 06:43 AM
Recover truncated file's contents on XFS? Tomasu Linux - Server 10 04-29-2008 08:08 AM
Help! tar file's name is truncated auden Linux - Newbie 1 03-02-2005 09:09 PM
Perl file conversion results in a truncated file kshaffer Programming 0 01-31-2005 02:31 PM > Forums > Enterprise Linux Forums > Linux - Enterprise

All times are GMT -5. The time now is 10:22 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration