Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
up vote 1 down vote accepted

Show the cron logs that prove this.

Perhaps cron or the system runs on a different timezone?

share|improve this answer
You're right. See my answer for more details. – ℝaphink May 25 '12 at 11:11

Try this:

0 2-18/8 * * * /path/to/your/script
share|improve this answer

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 to Europe/Zurich. It seems cron was restarted at a time when /etc/timezone contained UTC, 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:

May 25 08:19:57 ip-10-50-81-194 sshd[6216]: pam_unix(sshd:session): session opened for user root by (uid=0)
May 25 06:25:01 ip-10-50-81-194 CRON[6385]: pam_unix(cron:session): session opened for user root by (uid=0)
May 25 06:29:44 ip-10-50-81-194 CRON[6385]: pam_unix(cron:session): session closed for user root
May 25 08:53:36 ip-10-50-81-194 sudo:   nagios : TTY=unknown ; PWD=/ ; USER=root ; COMMAND=/opt/nagios-plugins/

Since collectd is properly running in Europe/Zurich, it shows jobs starting at 2AM (midnight UTC), 10AM (8AM UTC), etc.

share|improve this answer

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.

share|improve this answer
As said in my answer, I don't have a TZ variable on the command line. It's a problem that came from restarting cron at a point when /etc/timezone contained UTC. – ℝaphink May 25 '12 at 10:03

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


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.

share|improve this answer
See my answer for the explanation. – ℝaphink May 25 '12 at 11:11

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.