PDA

View Full Version : run script upon network connection similar to if-up.d


mano the shark
16th January 2010, 05:54 PM
I recently switched from ubuntu to fedora and had a script to mount and umount sshfs when the network changed states. I placed the scripts in /etc/network/if-up.d/ and /etc/network/if-down.d/ and they were run any time the network went up or down. The closest thing I've been able to find is editing the ifup and ifdown scripts in /etc/sysconfig/network-scripting/, but that looks like it would be broken after an update. I'd also rather not use a script with ping because that wouldn't work well when the network goes up and down several times.

I've been looking for a while and haven't been able to find a method similar to debian on fedora. Is there something I overlooked?

mano the shark
23rd January 2010, 03:49 PM
there has to be a way that applications are notified of the network status

pankajp
23rd January 2010, 04:12 PM

Add the script which you want to run on network events (up/down) in the directory /etc/NetworkManager/dispatcher.d/. Choose a name depending on the priority of the script (just as in startup init services scripts).
Example, here are the contents of a simple /etc/NetworkManager/dispatcher.d/10-sendmail

#!/bin/sh

if [ "$2" = "up" ] || [ "$2" = "down" ]; then
/sbin/service sendmail reload || :
fi

mano the shark
23rd January 2010, 07:42 PM
Thanks, that is what I was looking for. Now I need to get selinux to allow sshfs to work without being put in permissive first, but I'll look that up later.