2

is it possible to tell network manager to run a script when network connection gets down (and it can't reconnect)?

e,g: I have A bug in my network card driver, and sometimes NM fails to connect, a script can fix it` and I want it to be run each time network-manger can't connect, how do I do it?

2
  • I asked for failed connecting time, he asked for successfull connecting time, but thanks anyway - a small modification to his answer solve it for me - I just should put the script in /etc/network/if-post-down.d/.
    – Ohad Cohen
    Feb 1, 2015 at 0:43
  • In that answer, both situation is discussed.
    – g_p
    Feb 1, 2015 at 6:14

2 Answers 2

5

it's not part of network manager - but network manager uses 'ifupdown' to connect the internet, and ifupdown let you run scripts on connecting (turning interface up) or disconnecting (turning the interface down)

all you should do is to put your script in one of the following directories under /etc/network/:

if-pre-up.d/ - to be run before connecting

if-up.d/ - to be run after getting connected

if-down.d/ - to be run before disconnecting

if-post-down.d/ - to be run after getting disconnected

it does not do the exact thing i were looking for - as it do not detect problems and run the script only afterward - but since I do not care for the script to be run more times - i've put it in if-pre-up.d, so it runs before each time I connect the internet.

0

Quick answer: yes.

Long answer, more than "telling" NM to do something the easiest might be to check if NM is up/down before running your script. See example: https://wiki.archlinux.org/index.php/NetworkManager#Checking_if_networking_is_up_inside_a_cron_job_or_script

Making NM do something in between status changes I'd imagine involves changing the NM code itself.

Can you provide more details on what you are trying to accomplish?

2
  • see my comment above - I finnaly found that NM (or something else, but NM uses it as backend) has a mechanism for running scripts when network is up/down. thanks anyway
    – Ohad Cohen
    Feb 1, 2015 at 0:58
  • 1
    @ohad cohen: you should add an answer stating what is the way to do this so that future readers can find the solution easily.
    – heemayl
    Feb 1, 2015 at 10:01

Not the answer you're looking for? Browse other questions tagged .