LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (https://www.linuxquestions.org/questions/linux-networking-3/)
-   -   how to run script on event ppp0 interface going down ? (https://www.linuxquestions.org/questions/linux-networking-3/how-to-run-script-on-event-ppp0-interface-going-down-149735/)

qwijibow 02-23-2004 07:02 PM

how to run script on event ppp0 interface going down ?
 
Hello Fellow Penguin Huggers :)

i have a sucky dial-up ISP that hangs up every 2 hours of connection time.
and i want to leave my pc overnight to download large files.

is there anyway i could detect that the internet has gone down,
and run this sequence of commands....
Quote:

killall wget
/sbin/ifup ppp0
wget -ci DownloadURLS.list
thankyou.

ilikejam 02-23-2004 08:57 PM

Hi.

I think I've got it.

Start this script. You'll have to run it as root to get access to ifconfig. Adjust the sleep number to suit (it's 5 seconds at the moment - that's probably a bit short, YMMV)

Here's the script:

Code:

#!/bin/bash
while true ; do
    ifconfig | grep ppp0 &> /dev/null
    if [ $? != 0 ] ; then
        killall wget
        /sbin/ifup ppp0
        wget -ci DownloadURLS.list &
    fi
sleep 5
done

The script will run for ever, unless stopped by you.

Hope that helps.

Dave

Edit: Added & to end of wget -ci line

qwijibow 02-23-2004 09:07 PM

ah yes, that works great thanks !!

i though about somthing similar but decided it would eat all my cpu...
didnt realise BASH had a sleep function lol....

thanX for the script.

ilikejam 02-23-2004 09:08 PM

Did you get the last edit? The ampersand's important.

Dave

qwijibow 02-24-2004 06:08 AM

yep thats in there...
(also had to change ifconfig to /sbin/ifconfig if any1 else is reading this)

thanKs


All times are GMT -5. The time now is 01:46 PM.