Run command when network goes down?

Hi,

I’m using rsync via cron to synchronize files on my laptop with a drive on my network. This usually works fine, but because I’m doing it over a WLAN, I run into problems if the network connection fails. The script that cron runs checks for a network connection before running rsync, but if the network goes down after that check, I run into problems.

I thought I could solve this if I were able to kill rsync automatically if the network goes down. Is there some way to configure this? I tried putting a script with “killall rsync” into /etc/sysconfig/network/if-down, but the script was not executed. Does anyone know how to make this work, or know of a better option?

Thanks for your help!

(SuSE 11.0; KDE 3.5; using knetworkmanager)

The problem is that the network going down, as opposed to the network being explicitly taken down, is not something that’s easy to detect. From the standpoint of an app, a down link is hard to distinguish from one that’s taking a long time to reply.

However rsync has a --timeout option which you could use to shutdown rsync if it takes too long to get any response.