Setting timeout for cron jobs

Do Ubuntu Linux cron (Vixie cron?) support setting timeout for its jobs?

Specifically, the process would be killed after X seconds unless it finishes successfully by then.

I have had some cases where tasks have been hanging due to network connectivity and various issues. The process are left to hanging forever unless you manually clean up and kill them.


Solution 1:

On Ubuntu the command timeout exists, which is part of coreutils. You can use it like this to set a timeout. Older versions of Debian/Ubuntu didn't build and include this command, but there is a comparable timeout package that you can install.

# puppet shouldn't take more then 40 minutes!
47 * * * * root /usr/bin/timeout 2400 /usr/bin/puppet agent ...