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 Answers2

4

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?

keponk
  • 213