Article View: comp.unix.admin
Article #4069Re: tail -f and log file rotation
From: Cyrille Lefevre
Date: Fri, 02 Mar 2001 03:25
Date: Fri, 02 Mar 2001 03:25
67 lines
3659 bytes
3659 bytes
Nate Eldredge <neldredge@hmc.edu> writes:
> "Vince" <vlasfargues@yahoo.com> writes:
>
> > I suppose I'm not the only one to have the following problem:
> >
> > I use "tail -f" to get the new entries in the syslog file. But when the file
> > is renamed (because it's too big or too old), tail is stuck on the renamed
> > file, which is not appended anymore.
> > I've heard about "tailf" (linux) or the option "tail -fname", but there is
> > nothing like that on Solaris, HP-UX or AIX.
tail -f exists under all flavors of unices but doesn't work on renamed file.
BSD flavors have tail -F which handle this case.
> > Where can I get some source code to build my own tail that will support this
> > option or will follow and returned the entries inserted in the new syslog
> > file?
ftp://ftp.freebsd.org/pub/FreeBSD/branches/-current/src/usr.bin/tail/
BSD tail -F can be easily simulated this way:
#!/bin/sh
trap '[ -n "$pid" ] && kill $pid' 2 3 15
file=$1 tmout=60
while sleep $tmout; do
[ -f "$file" ] || continue
new=`ls -i "$file" 2>/dev/null | awk '{print $1}'`
if [ "$old" != "$new" ]; then
old=$new
[ -n "$pid" ] && kill $pid
tail -f "$file" & pid=$!
fi
done
> Get GNU tail (from the Textutils at ftp.gnu.org) and use the
> --follow=filename option.
GNU tail -f doesn't work on renamed or removed files. try this and see:
ls >> /tmp/log
gtail -f log &
ls >> /tmp/log
(ok)
mv /tmp/log /tmp/olog
ls >> /tmp/log
(nothing)
rm /tmp/olog
ls >> /tmp/log
(nothing)
the lesson is... GNU tools aren't good everywhere :)
PS : Vince, when you crosspost, don't forget to put a followup-to.
also, don't crosspost on groups w/ different languages as you do (fr).
fu2 cua
Cyrille.
--
home: mailto:clefevre%no-spam@poboxes.com.invalid | UNIX is user-friendly;
work: mailto:Cyrille.Lefevre%no-spam@edf.fr.invalid | it's just particular
Supprimer "%no-spam" et ".invalid" pour me repondre. | about who it chooses
Remove "%no-spam" and ".invalid" to answer me back. | to be friends with.
Technical Details
Message-ID:
<1ysg26oa.fsf@gits.dyndns.org>Path:
arc1-ca.pugleaf.net!supernews.google.com!sn-xit-03!supernews.com!freenix!isdnet!isdnethub!not-for-mailReferences:
<t9thrboar8bh8e@corp.supernews.com> <833dcxhv24.fsf@mercury.st.hmc.edu>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 115614,28d4954342c36ebf
X-Google-Attributes: gid115614,public
X-Google-Thread: 11035d,28d4954342c36ebf
X-Google-Attributes: gid11035d,public
X-Google-Thread: 110f2c,28d4954342c36ebf
X-Google-Attributes: gid110f2c,public
X-Google-Thread: 1020c6,28d4954342c36ebf
X-Google-Attributes: gid1020c6,public
X-Google-ArrivalTime: 2001-03-01 19:28:03 PST
Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-03!supernews.com!freenix!isdnet!isdnethub!not-for-mail
From: Cyrille Lefevre <clefevre%no-spam@poboxes.com.invalid>
Newsgroups: comp.unix.admin,comp.unix.aix,comp.unix.solaris,fr.comp.os.unix
Subject: Re: tail -f and log file rotation
Followup-To: comp.unix.admin
Date: 02 Mar 2001 04:25:41 +0100
Organization: ACME
Lines: 67
Message-ID: <1ysg26oa.fsf@gits.dyndns.org>
References: <t9thrboar8bh8e@corp.supernews.com> <833dcxhv24.fsf@mercury.st.hmc.edu>
Reply-To: Cyrille Lefevre <clefevre%no-spam@poboxes.com.invalid>
NNTP-Posting-Host: d165.dhcp212-231.cybercable.fr
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
X-Trace: news2.isdnet.net 983503543 4765 212.198.231.165 (2 Mar 2001 03:25:43 GMT)
X-Complaints-To: abuse@isdnet.net
NNTP-Posting-Date: 2 Mar 2001 03:25:43 GMT
X-Face: V|+c;4!|B?E%BE^{E6);aI.[<<r#uCVjK"~Ke!@0vxS/.,wki/c|uVnNV!BA-_gY2sfoGc3
f{#/$PT>97Zd*>^#%Y5Cxv;%Y[PT-LW3;A:fRrJ8+^k"e7@+30g0YD0*^^3jgyShN7o?a]C
la*Zv'5NA,=963bM%J^o]C
User-Agent: Gnus/5.0807 (Gnus v5.8.7) XEmacs/21.1 (Channel Islands)