12

As I know crontab has those fields, starting by left to right.

1   minutes 0-59
2   hours 0-23
3   days of month 0-31
4   month 1-12
5   day of the week 0-6
6   command

I want to run foo command every 15 days at 15:30 This is correct because run command 1 and 15 of the month month has 30 days(31 some) so is run every 15 days

30 15 1,15 * * /sbin/foo -a 1> /dev/null

Is also correct this syntax?

30 15 */15 * * /sbin/foo -a 1> /dev/null

System is Slackware Linux which use Dillon Cron

5
  • 5
    There is no "mail-to" field; there's a MAILTO variable, but you set that on a line by itself (before the job entries that it applies to). Nov 20, 2020 at 6:49
  • The mailto doesn't work on cron dillon, cron.log said "Nov 20 20:06:01 crond[1634]: failed parsing crontab for user root: MAILTO=root "
    – elbarna
    Nov 20, 2020 at 20:28
  • Interesting; I don't have a copy to experiment with, but from the docs it looks like Dillon cron doesn't support any variables in crontab files. Nov 20, 2020 at 20:37
  • 30 15 */2 * 0 should give a nice 14 day rhythm, depending on the job that might also be an option. Nov 20, 2020 at 21:53
  • For an alternative see man systemd.timer. I like the Persistent feature: "This is useful to catch up on missed runs of the service when the system was powered down."
    – VPfB
    Nov 21, 2020 at 14:15

1 Answer 1

18

This syntax 30 15 */15 * * is correct, but it is not doing the same with this 30 15 1,15 * *.

The latter will execute command at 1st and 15th of the month, as it has fixed comma separated values for the "day of month" field.

The / defines steps, that means */15 will execute every 15 days, starting from 1, that means: 1st, 16th (for all months) and also 31th (for any month having 31 days).


As man crontab(5) says, step values can be used in conjunction with ranges. So if you want to have the same result using the / syntax you could do: 30 15 1-15/14 * * which means 30 15 1,15 * *.

Another example, if you want to run every 15 days, but on 5th and 20th of every month: 5-20/15. Of course, for this case, it is more readable to write 5,20. But combining the range with the steps, enables defining the start-end of the ranged execution.

For Day 1,3,5,7 etc of the Month: */2

For Day 2,4,6,8 etc of the Month: 2-30/2

For Minutes(0-59) and Hours(0-23), the first valid value is 0 so this: 0 */2 * * * means at 00:00, 02:00, 04:00 etc.

2
  • 1
    I thought */n means every multiple of n. Or is that only for fields whose values start at 0?
    – Barmar
    Nov 20, 2020 at 17:07
  • 3
    Yes, for minute or hour, */n (without a range at the "dividend") will start from 0, so it is the multiple of n. For Day Of Month, where 1 is the first valid value, it starts from 1, so it is "multiple of n" +1.
    – thanasisp
    Nov 20, 2020 at 17:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .