FINALLY, with the help of fcron , judicious use of Bash debugging, and a lot of freaking around, I have managed to get scheduled cron jobs running the way I want to.

For a supposedly lightweight process, there are actually a ton of ‘gotchas’ which will likely trip you up. Here are some tips:

  1. Ensure the right permissions for the cron job - cron will ignore scripts that have certain non-standard permissions, for security.
  2. Ensure the right filename for the cron job script - it will ignore certain extensions or variations on the end of the script file name!
  3. Ensure ALL symbolic links in your cron job scripts are resolved to actual paths - for some reason cron doesn’t like this, probably a security measure again.
  4. Use fcron with anacron syntax to ensure ‘intelligent’ scheduling - e.g. if the computer is turned off most of the week, when it is turned back on, it will still run the weekly job, instead of waiting a further 7 days!
  5. Make sure you ‘cd’ into the working directory AS PART of the cron job before you attempt to use any relative (non absolute) paths. And you should do this instead of specifying absolute paths for large scripts, because of the potential to make mistakes, which will take longer to test!
  6. Use nohup and a Bash ’trap’ error logger to log complete runs. Log the WHOLE output of the Bash cron’d script, using STDERR and STDOUT concatenation.
  7. Use screen to run jobs so you can inspect running jobs when you need to.
  8. Use ionice and nice liberally so that you can avoid system lockups due to multiple processing scheduled jobs hogging the system resources!
  9. Turn off ‘fcron’s ‘serial’ parameter so that multiple jobs can run at the same time - this is essential if one running job happens to overlap another. Fcron with anaocron syntax will usually figure out the rest.

No wonder Jenkins is so popular!