When scheduling a job every x
hours, how to tell which hours will be picked?
For example, we have a cronjob set for */8
which is run at 2AM, 10AM, etc. instead of midnight, 8AM, etc.
When scheduling a job every x
hours, how to tell which hours will be picked?
For example, we have a cronjob set for */8
which is run at 2AM, 10AM, etc. instead of midnight, 8AM, etc.
Try this:
Show the cron logs that prove this.
Perhaps cron or the system runs on a different timezone?
To clarify the situation, we actually saw graphs that showed that the job started at 2AM, 10AM, etc.
Upon investigating the issue, we found that cron is launched with
TZ=UTC
, while/etc/timezone
is set toEurope/Zurich
. It seems cron was restarted at a time when/etc/timezone
containedUTC
, and was never restarted since/etc/timezone
was changed.As a result, cron not only launches its jobs in UTC, it also logs in UTC, which results in
/var/log/auth.log
containing things like:Since collectd is properly running in
Europe/Zurich
, it shows jobs starting at 2AM (midnight UTC), 10AM (8AM UTC), etc.passing TZ variable will always make the script run in that timezone irrespective of your system local timezone. If you don't want that behavior remove the TZ variable from the line.
The * stand for firs-last so if you set up cronjob like
0 */2 * * * echo "runat midn, 2am, 4am ..., everyday"
should be the same as
0 0-23/2 * * * echo "runat midn, 2am, 4am ..., everyday"
so in your example jobs like
0 0-23/8 * * * command
or
0 */8 * * * command
should run at 0:00 8:00 16:00 ...Maybe your time or time setting are wrong. Show us your crontab -l output and check your current time and time zone settings.