> I got a small script that I use to backup my mailserver every saturday. My > problem is that a few times a year the machine i use for backup is taken > offsite (we haul or office around a lot). Then the script stalls because > the nfs mount fails. Naturally this becomes a problem. Could someone supply > me som sh or bash scripting code so I can make sure that this will not > happen, and that the script stops and just starts cyrus (maybe with a mail > to someone as well). > It's been a while since I wrote a shell script--I always use Perl nowadays because it provides a superset of the features and a more consistent syntax.
Anyway, normally when I have to deal with something like this in Perl I just set up an alarm: ---- $SIG{ALRM} = sub {$mount_failed=1}; alarm 120; # call me back in two minutes eval {do_something_that_might_timeout()}; alarm 0; # turn alarm off if ($mount_failed) { # do something } else { # do a different thing } ---- There's probably a way of handling signals in Bash, but I'm not sure what it is. You could just replace your shell script with Perl--stick backticks around calls to shell stuff to get them executed as shell commands rather than Perl statements.