bash: run a command for n minutes, then SIGHUP it bash: run a command for n minutes, then SIGHUP it shell shell

bash: run a command for n minutes, then SIGHUP it


See the timeout command now in most GNU/Linux distros.

timeout -sHUP 10m command

The same functionality can be achieved with http://www.pixelbeat.org/scripts/timeout


Try it with this one, it starts your command in the background, stores it's PID in $P, waits for some time and kills it with a SIGHUP.

yourCommand & PID=$!sleep ${someMinutes}mkill -HUP $PID

Cheers

PS: that assumes a sleep that knows about Nm (minutes), else, you might want to do some math :)


n=5some_command &pid=$!at now + $n minutes <<<"kill -HUP $pid"

The benefit of using at over waiting for sleep is that your script wont block waiting for the sleep to expire. You can go and do other things and at will asynchronously fire at the specified time. Depending on your script that may be a very important feature to have.