On Fri, May 26, 2000 at 02:10:52PM +1000, Jeff Waugh wrote:
> > whats wrong with:
> >
> >  fgrep Connect: /var/log/messages* | tail -1
> 
> - 8< - snip - 8< -
> 
> > so what do you gain by using tac ?
> 
> 
> Well, I wanted the very latest occurance of a ppp connect, and due to the
> layout of log-rotated messages files, I had to use cat.
> 
> The above fgrep wouldn't return the most recent occurance, it would return
> an (unreliable) *last* known occurance. Unreliable because of the
> log-rotated filenames and appended logs, as demonstrated here...

good point, try this then

> --- [pppinfo] ---
> 
> #!/bin/sh
> 
> tac /var/log/messages* | awk '/CONNECT/ { print("  ",$0); }' | head -n 1
> 
> pppstats $* | awk '/[0-9]/ { printf("   IN:\t%5.3f Mb\n   OUT:\t%5.3f Mb
> \n\n",$1/1024000,$7/1024000) }'
> 
> ---

for f in /var/log/messages*; do fgrep CONNECT $f && break; done \
 | tail -1 | sed 's/^/  /'

the sed is just so you still get your precious indent ;)


(tac would have to check each byte in the file for '\n', whereas fgrep
(in this case) only has to check every 7(ish))

-- 
 - Gus
--
SLUG - Sydney Linux Users Group Mailing List - http://www.slug.org.au
To unsubscribe send email to [EMAIL PROTECTED] with
unsubscribe in the text

Reply via email to