shellcroncron-taskcrontrigger

Is there a command for cron job to run after every 14th of a month which should be a saturday(first Saturday after 14th or third Saturday of month)


Is there a command for the cron job to run after every 14th of a month which should be a Saturday(only on the first Saturday after 14th or the third Saturday of the month) at 11.59 pm

I need to know the command of the cron job

59 23 * * 6 [ "$(date +%d -d tomorrow)" -gt 14 ] && [ "$(date +%u -d tomorrow)" -eq 6 ] && the task

I have used the above expression. but still unsure if any other expression can do the same job more efficiently.


Solution

  • UPDATE: @jhnc found that the spec (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/crontab.html) indicates that while there is a lot of "ANDing", sometimes there is "ORing": "Finally, if either the month or day of month is specified as an element or list, and the day of week is also specified as an element or list, then any day matching either the month and day of month, or the day of week, shall be matched."

    Based on that, I think your original approach is probably the right one.

    ORIGINAL ANSWER:

    cron fields are "anded" together, and ranges are permitted, so this should work:

    59 23 14-31 * 6 <the task>