Run a python script when connected to internet

Unix & Linux Asked by CutePoison on December 5, 2020

I have a simple python script and a file:

python -c "from hello import hello; hello()"


made it executeable and placed in the if-up.d directory. Being in the directory and running ./ it works as it should. But disconnecting and re-connecting does not trigger the script.

Even it the script is just echo "hello">>out.txt it still doesn’t get executed. My user is owner of the script (running ubuntu 20.04)

Any idea?

One Answer

You can use the code below with setting the correct interface name :

    if [ "$IFACE" = <interface-name> ]; then 
        python <path_to_your_script>.py

Don't forget to make it executable :

sudo chmod +x <path_to_your_script>.sh 

Also if your interface is managed by NetworkManager this wil not work.

Answered by Reda Salih on December 5, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP