Tailing rotating log files?
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix questions > Tailing rotating log files?




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    Tailing rotating log files?  
Roy Smith


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
12-17-04 12:44 AM

I've got a program which write a log to foo.log, and I want to watch
the contents of that file; tail -f would work fine, but for one
hitch.  Each time the program restarts, it closes the log file, moves
the old log to foo.log.bak, and starts a new foo.log.

I know some tails have a -F which does exactly that, but I'm on
solaris, and the solaris tail doesn't support -F.  Is there a simple
way to fake this out on solaris?





[ Post a follow-up to this message ]



    Re: Tailing rotating log files?  
Bill Marcum


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
12-17-04 12:44 AM

On 14 Dec 2004 11:14:19 -0500, Roy Smith
<roy@panix.com> wrote:
> I've got a program which write a log to foo.log, and I want to watch
> the contents of that file; tail -f would work fine, but for one
> hitch.  Each time the program restarts, it closes the log file, moves
> the old log to foo.log.bak, and starts a new foo.log.
>
> I know some tails have a -F which does exactly that, but I'm on
> solaris, and the solaris tail doesn't support -F.  Is there a simple
> way to fake this out on solaris?

Use a crontab to check the size, mtime, and/or inode number of foo.log;
have it restart your script if the inode changes or the size decreases.


--
cowsay -b "Prepare to be assimoolated! "





[ Post a follow-up to this message ]



    Re: Tailing rotating log files?  
Ed Morton


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
12-17-04 12:44 AM



Roy Smith wrote:
> I've got a program which write a log to foo.log, and I want to watch
> the contents of that file; tail -f would work fine, but for one
> hitch.  Each time the program restarts, it closes the log file, moves
> the old log to foo.log.bak, and starts a new foo.log.
>
> I know some tails have a -F which does exactly that, but I'm on
> solaris, and the solaris tail doesn't support -F.  Is there a simple
> way to fake this out on solaris?

You could do something like this (untested):

_file="$1"
_start=0
while :
do
_end=`wc -l < "$_file"`
_end="${_end##* }"
if (( $_end < $_start ))
then
# the file has been moved to a backup
_tailFile="${_file}.bak"
_end=`wc -l < "$_tailFile"`
_end="${_end##* }"
else
_tailFile="$_file"
fi
if (( $_end > $_start ))
then
_start=$(( $_start + 1 ))
sed -n "${_start},${_end}p" "$_tailFile"
fi
if [ "$_tailFile" = "$_file" ]
then
_start="$_end"
else
_start=0
fi
sleep 1
done

I didn't spend very long thinking about the above (which I tweaked from
a different script) but hopefully you get the idea - just use sed to
print out the number of lines added to the file (or it's backup if just
created) in about the past second.

Regards,

Ed.





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 01:01 PM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register