How to run a script, depending on internet connection

Add your script to /etc/network/if-up.d/. Name your script without a '.sh' extension.

Also after adding script run chmod +x /etc/network/if-up.d/yourscriptname to give necessary permission.

Make sure the network interface (e.g. wlan0 or eth0) that should trigger your script when turned on is mentioned in the file /etc/network/interfaces.


Editor's note: Cuttlefish hasn't been updated since 2012 and is not in any current Ubuntu repositories

Ubuntu 12.04

  • Install Cuttlefish: A simple tool, which realises reflexes on your computer by executing actions when specific events are triggered.
  • Open Cuttlefish and click on New.

    Step-1

    • Give it a name, and change Activated by stimulus option to ON.
    • Click on Stimulus, select the category Network and type Connect to WLAN. Click OK.

    Step 2

    • You can also select the SSID of wireless network and you have an option of whether or not to check this on startup.

    Step 3

    • Now you will have to specify a reaction. Go to Reaction tab, and click add. Select Applications from the category and Start Application (in advanced mode) from type.

    Step 4

    • Now specify the script which you want to run in executable option. You can even pass parameters to the script.

    Step-5

    • And that's it! Also make sure that you add Cuttlefish in startup applications. Go to Edit > Preferences and enable the autostart option.

    Step-6


I will answer this part of the OP question: "I would love to have this mount automatically"

My favorite tool for automounting network shares is autofs: https://help.ubuntu.com/community/Autofs

AutoFS is my tool of choice to mount my NAS - for all my laptops and workstations.

"autofs is a program for automatically mounting directories on an as-needed basis. Auto-mounts are mounted only as they are accessed, and are unmounted after a period of inactivity. Because of this, automounting NFS/Samba shares conserves bandwidth and offers better overall performance compared to static mounts via fstab."