> 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...
A normal "cat /var/log/messages*" looks like this:
fairly recent \
|| + /var/log/messages
\/ |
most recent /
fairly old \
|| + /var/log/messages.1
\/ |
fairly recent /
old \
|| + /var/log/messages.2
\/ |
fairly old /
rolling stones \
|| + /var/log/messages.3
\/ |
old /
Which is not the best direction to have to find the most recent given event.
By taccing the files (tac /var/log/messages*), I got something more like
this:
most recent /var/log/messages
fairly recent
fairly old /var/log/messages..
old
rolling stones /var/log/messages...
Which is much closer to the direction I want to search in. Then, all that's
left to do is find the first occurance of the string (fgrep Connect:) and
return the first of that list (head -1).
Anyway, the resultant script was this:
--- [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) }'
---
(I've separated the lines to make it easier to read - the pppstats line will
get cut off at 76 characters, so make sure you put it in it correctly)
If you pass it "-w <integer>", it will report every <integer> seconds,
telling you the amount of traffic that has passed through. Check man
pppstats for the real details, you can pass as many pppstats arguments as
you want. Without the -w parameter, it will just tell you your total
throughput for that ppp session.
Just in case anyone's interested. :)
- Jeff
-- [EMAIL PROTECTED] -------------------------------------------------
w: http://advogato.org/person/jdub/
i: 16341281 (jdub!)
q: "She said she loved my mind, though by most accounts I had
already lost it."
--
SLUG - Sydney Linux Users Group Mailing List - http://www.slug.org.au
To unsubscribe send email to [EMAIL PROTECTED] with
unsubscribe in the text