In article <WG8Pd.22241$(E-Mail Removed)>, Kevin Brown wrote:
>I need to write a script which watches the logs and shows me when a
>PPPoE connection fails.
From: Mendel Cooper <(E-Mail Removed)>
Newsgroups: comp.os.linux.announce
Subject: Advanced Bash Scripting Guide: ver. 3.2 update
Date: Thu, 10 Feb 2005 13:23:23 CST
Find that at any LDP mirror, or
http://tldp.org/guides.html#abs
>By going into the logs I can see all of the
>times it has failed by typing:
>
>cat /var/log/messages | grep terminated
We have another candidate for the 'Useless Use Of Cat' award!!! ;-)
Actually, a problem here - if 'terminated' shows up _anywhere_ in the
logs (here, /var/log/messages gets rotated weekly) it is found by grep.
>But I want to use that as a trigger so that when a new line in the file
>shows up with the word 'terminated', it will run another script which
>will update the load balancing w/ the new PPP IP address.
while true ; do
NOW=`date +"%d %H:%M"`
grep "$NOW" /var/log/messages | grep -q terminated
if [ $? = "0" ] ; then
run.other.script
fi
sleep 30
done
See also the man pages. Briefly, endless loop, which assigns the current
day of month (%d), a space, and the time in hours/minutes to the variable
'NOW'. The next line then greps for that in /var/log/messages (the quouts
around the variable protect the space it contains) to get messages for the
current minute, and passes that to a quiet grep (no output needed) for the
desired word. If the word is found, run your script. Then sleep for 30 seconds
and repeat endlessly.
The thing is, there is (quoting Larry Wall) "more than one way to do it".
You might also look at /etc/ppp/ip-down, and see if that is being run when
the link fails - and run a restart out of there.
Old guy