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!

Related Questions

Sed command writes the expression in outer ifmodule

1  Asked on January 9, 2021 by ariana-williams


Netctl is slow in arch linux

1  Asked on January 9, 2021 by fenil-shah


How to default `ps aux` to `ww`?

0  Asked on January 7, 2021 by nicholas-dipiazza


Earphone’s mic does’t work on fedora linux

0  Asked on January 6, 2021 by vedant-nandwana


Parallelize a Bash FOR Loop

10  Asked on January 6, 2021 by ravnoor-s-gill


List only bind mounts

5  Asked on January 6, 2021 by l0b0


Addition with ‘sed’

12  Asked on January 5, 2021 by luigi-tiburzi


Muon is stuck on lubuntu cosmic. How do I get off this dead end?

1  Asked on January 5, 2021 by cw-holeman-ii


Where are defined the man pages grouping descriptions?

1  Asked on January 5, 2021 by lus-gustavo-monezi


xrandr three monitors

2  Asked on January 5, 2021 by ben-flowers


Adding iptables rules after implementing fail2ban

1  Asked on January 5, 2021 by mike-dank


Ask a Question

Get help from others!

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