14

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.

2 Answers 2

30

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 ...
2
  • 4
    The duration can also have a suffix ("s" for seconds, "m" for minutes, "h" for hours and "d" for days). So for better readability, the above could also be written as 47 * * * * root /usr/bin/timeout 40m /usr/bin/puppet agent ...
    – smoove666
    Apr 21, 2015 at 8:56
  • 1
    No it can't. at least not with the implementation I had when writing this question. The new version in coreutils has the s suffix. The version I had on older Debian systems didn't.
    – Zoredache
    Apr 21, 2015 at 15:21
-3

I don't think this is possible. You'll have to build the check into your application.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .