How to schedule a Cron job to run 4th week of the year

后端 未结 2 992
逝去的感伤
逝去的感伤 2021-01-19 04:48

I work on an application that uses native Unix CRON tab for scheduling jobs. the description of parameters are as follows :

Minute, Hour, Da_of_Week(1-7, 1=         


        
2条回答
  •  心在旅途
    2021-01-19 05:04

    You have to put a condition in your crontab to do that. Your cron will look something like this,

     0 20 1-7 1 *  root [ `date +%a` == "Mon" ] && /run/some/script
    

    cron 0 20 1-7 1 * runs at 8pm everyday from 1st to 7th in the month of January.

    Following checks that the day is Monday before executing your script.

     [ `date +%a` == "Mon" ]
    

    With this, script will run on the 7th January 2019, which is within the first week of the year.

    $ cal 01 2019
        January 2019    
    Su Mo Tu We Th Fr Sa
           1  2  3  4  5
     6  7  8  9 10 11 12
    13 14 15 16 17 18 19
    20 21 22 23 24 25 26
    27 28 29 30 31
    

提交回复
热议问题