NetBSD-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: crontab fun

Patrick Welche wrote:
Quoting the fine crontab(5) manual:

       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 (ie,
       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.

How can you run a command when _both_ fields match?

If the rule were _both_ and I wanted _either_, I could write 2 lines
in crontab. The opposite isn't obvious to me. A use case for _both_
would be "run this backup every Friday unless it's the first of the
month (because the different monthly backup is running)" - and I can't
believe I'm the first one to encounter this ;-)

I'd set up a cron job to run a shell script every Friday; the script would then call `date +%d` and see whether it is less than 5 (or 6, depending on whether your week starts with Sunday or Monday) and run the backup differently...

You might also look up Vixie cron, as that supports an extended syntax for specifying more complex rules.


Home | Main Index | Thread Index | Old Index