I have a scheduled cron job (which is actually a shell script). I'd like to limit the script execution time as it can work unacceptably long. For some reason I can not limit the script execution time from inside the script. Actually, I want my system to force the task termination if it runs more than N hours. Please advise.
From the interactive shell, you can enter the command you want to run at that time. If you want to run multiple commands, press enter after each command and type the command on the new at> prompt. Once you're done entering commands, press Ctrl-D on an empty at> prompt to exit the interactive shell.
The Timelimit program runs a given command then terminates the process after a specified time using a given signal. It initially passes a warning signal, and then after a timeout, it sends the kill signal. Unlike the timeout option, Timelimit has more options such as killsig, warnsig, killtime, and warntime.
sleep Command Bash Script Example Here is a simple example: #!/bin/bash echo "Hi, I'm sleeping for 5 seconds..." sleep 5 echo "all Done."
tiny 4. /bin/ed Choose 1-4 [1]: Make a new line at the bottom of this file and insert the following code. Of course, replace our example script with the command or script you wish to execute, but keep the */5 * * * * part as that is what tells cron to execute our job every 5 minutes. Exit this file and save changes.
I'm responding by myself just because none answered.
0 * * * * timeout -s 9 3540 /path/to/your_command.sh
will send a SIGINT to your command if it hasn't completed in 59 minutes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With