Cron is a time-based job scheduler that comes default on most Unix like operatings systems and servers. It is designed to run command on a defined schedule. The crontab syntax is commonly used outside of the cron daemon (such as in Kuberenetes CronJobs) to define recuring schedules.
The name cron most likel comes from the Greek word for time, χρόνος (chronos).
The longest possible time between two cron jobs being run is eight years, running on each leap day
0 0 29 2 * . While leap days normally happen every four years, they do not occur in centennial years (e.g. 1800, 1900, etc...) that are not evenly divisible by 400.
In your crontab add
*/5 * * * *.
The crontab syntax is pretty flexible but there is no one schedule that will run every two weeks. The trick is to run your command every week and to add a condition so the command is executed only on the correct weeks.
- Cron converts
%to a newline character so we need to escape it (
\) in the command to get the right output
- Retrieves the current week number
expr $(…) \% 2)
- Calculates the remainder of dividing the week number by 2. So
43 % 2 => 1
[ $(…) -eq 1 ] && /cmd
- Tests if it's an odd week (
-eq 1) and only executes the command when it's true. Use
-eq 0to run on even weeks
While the cron daemon is pretty battle tested and hardened, individual jobs can fail for a number of reason. For example, the path may not configured correctly, the schedule is wrong, or maybe the job ran but raised an exception.
For all of these cases we recommend Dead Man's Snitch to know when your cron jobs are failing to run or erroring.