PPP Script

Discussion in 'Linux Networking' started by Kevin Brown, Feb 11, 2005.

  1. Kevin Brown

    Kevin Brown Guest

    I need to write a script which watches the logs and shows me when a
    PPPoE connection fails. By going into the logs I can see all of the
    times it has failed by typing:

    cat /var/log/messages | grep terminated

    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.

    Thanks in advance,
    Kevin Brown.
     
    Kevin Brown, Feb 11, 2005
    #1
    1. Advertisements

  2. Kevin Brown

    Bit Twister Guest

    I would just ping the gateway myself.
    Bad choice

    grep terminated /var/log/messages > /dev/null
    if [ $? -eq 0 ] ; then
    whatever you want to do here
    fi
     
    Bit Twister, Feb 11, 2005
    #2
    1. Advertisements

  3. Kevin Brown

    Moe Trin Guest

    From: Mendel Cooper <>
    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
    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.
    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
     
    Moe Trin, Feb 12, 2005
    #3
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.