Results 1 to 4 of 4

Thread: cron running on incorrect days

  1. #1
    Join Date
    Sep 2009
    Beans
    6

    cron running on incorrect days

    Hi All,

    The following entry in my crontab is excecuted daily, when it should only run on the 1st and 16th of the month:

    30 4 1,16 * 0,6 touch /home/quser/testfile >/dev/null 2>&1
    30 2 1,16 * 1-5 touch /home/quser/testfile >/dev/null 2>&1

    Unless I'm missing something completely obvious, testfile should be created at 2:30 am Monday-Friday, and at 4:30 am on Saturday and Sunday, but only when it is the 1st or 16th of the month. However, testfile is created every day, either at 2:30 am (Monday-Friday) or 4:30 am (Saturday, Sunday).

    This is on Ubuntu Server 12.04.1 LTS, with the latest updates applied.

    Any idea what's going on?

    Thanks!

  2. #2
    Join Date
    Apr 2007
    Location
    Glasgow
    Beans
    308
    Distro
    Ubuntu

    Re: cron running on incorrect days

    Specifying day-of-month and day-of-week are treated as OR conditions, which is weird because all other fields are AND'd together.

    Have no idea why, but there's a stanza explains the situation in the crontab man page.

    Hope this helps,

  3. #3
    Join Date
    Nov 2008
    Location
    Sheffield, UK
    Beans
    1,514
    Distro
    Ubuntu

    Re: cron running on incorrect days

    Not sure if this will help:
    http://www.csgnetwork.com/crongen.html

  4. #4
    Join Date
    Sep 2009
    Beans
    6

    Re: cron running on incorrect days

    That was the problem... I was sure this was a bug, but apparently it's a feature. From man 5 crontab:

    " Note: The day of a command's execution can be specified by two fields —
    day of month, and day of week. If both fields are restricted (i.e.,
    aren't *), the command will be run when either field matches the cur‐
    rent time. For example,
    ``30 4 1,15 * 5'' would cause a command to be run at 4:30 am on the 1st
    and 15th of each month, plus every Friday. One can, however, achieve
    the desired result by adding a test to the command (see the last exam‐
    ple in EXAMPLE CRON FILE below)."

    Thanks!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •