I've got a cronjob which runs hourly that is occasionally taking too long to run, is there any way I can set a maximum runtime and the job gets killed if it exceeds that?
This is on an Ubuntu 10.04 server.
Thanks, jebw
Try the timeout
command. For example:
0 * * * * timeout -2 3540 /path/to/your_command.sh
will send a SIGINT to your command if it hasn't completed in 59 minutes.
usage: timeout [-signal] time command...
Nope. The way we do it is to make a script with a lock file and have the script check for that lock file before start running again, so it can check if it is already running and decide if it runs, if it waits for the other to end or if it kills the other before running.
A lock file is just a empty file or a file with the other script PID
saved somewhere like /var/run
or /var/lock
.
cakemox's answer is the best. Otherwise, just put the pid intoa file or use killall on anouther cronjob a minute earlier to kill the process.