Run every 2nd and 4th Saturday of the month

前端 未结 5 1064
执念已碎
执念已碎 2020-12-16 00:21

What\'s the cron (linux) syntax to have a job run on the 2nd and 4th Saturday of the month?

5条回答
  •  南笙
    南笙 (楼主)
    2020-12-16 01:04

    Expanding on @paxdiablo's reply, why not just put the addition into the crontab, instead of the script?

    #m h dom       mon dow command
    0  1 8-14,22-28 *   *   [ `date +\%u` = 6 ] && /path/to/myscript
    

    Note the backslash before %u, which is not needed when you try this on the command line, but it is needed in a crontab entry to ensure the shell gets to see the whole command.

    Doing it this way puts all the logic for selecting the proper day in the place your colleagues first look at, and you can run the script manually on another day if the need arises.

提交回复
热议问题