Start shell script on internet connection

Dec 16 2011 Published under Linux

At some point you might want to automatically run some script upon internet connection established. Place the following script in “/etc/NetworkManager/dispatcher.d/” directory and you are gold. The “90″ in the name of the script means that this script will be executed in the last 10% of all scripts if you have a bunch of scripts to execute when your interface starts[1].

#!/bin/bash
#/etc/NetworkManager/dispatcher.d/90filename.sh
 
IF=$1
STATUS=$2
 
if [ "$IF" == "wlan0 ]  # for wireless internet
then
    case "$2" in
        up)
        logger -s "NM Script up triggered"
        #place custom here
        ;;
        down)
        logger -s "NM Script down triggered"
        #place custom here
        ;;
        pre-up)
        logger -s "NM Script pre-up triggered"
        #place custom here
        ;;
        post-down)
        logger -s "NM Script post-down triggered"
        #place custom here
        ;;
        *)
        ;;
    esac
fi

Connect and disconnect internet and run the following command to make sure the script is functioning as expected.

$ sudo tail -f /var/log/syslog

ref:
[1] http://www.techytalk.info/start-script-on-network-manager-successfull-connection/

No responses yet

Comments are closed at this time.

Login