How could I make a script time out after nn minutes, if it's not finished by then? The practical context: I have a dozen or so of backup scripts in a directory "daily", and they are run by cron like this:> 0 23 * * 1-6 run-parts /root/dailySometimes one of the scripts hang, in which case the rest of the scripts are delayed more than can be allowed. - Jussi -- Jussi Hirvi * Green Spot NOTICE: Due to the rising energy costs, as well as current market conditions, the Light at the End of the Tunnel has been turned off. We apologise for the inconvenience.
Jussi Hirvi wrote:> How could I make a script time out after nn minutes, if it's not finished by > then? >I put this little test script together. It seems to work OK... #!/bin/bash timeoutseconds=5 pid=$$ (echo Will kill $pid in $timeoutseconds seconds; sleep $timeoutseconds; kill -1 $pid) & while true do echo Hello sleep 0.6 done You may need to vary the signal in the kill statement, depending on what you're running. Ian
On Wed, 2008-11-12 at 11:54 +0200, Jussi Hirvi wrote:> How could I make a script time out after nn minutes, if it's not finished by > then? > > The practical context: I have a dozen or so of backup scripts in a directory > "daily", and they are run by cron like this: > > 0 23 * * 1-6 run-parts /root/daily > > Sometimes one of the scripts hang, in which case the rest of the scripts are > delayed more than can be allowed.Do "man bash" and search for "trap". For those not familiar, it can be a little confusing, but it's well worth the effort, in terms of results and learning.> > - Jussi > <snip sig stuff>HTH -- Bill