0

I want to schedule a job for 3rd Friday of every month, 1 AM . I checked few cron entry websites for that didn't work for me.

I was also checking for some awk options for this so far not successful with that. Can you guys help me with that?

I tried to run this for today the cron is working fine but the script is running continuously at the same point and not getting completed :

0 1 15-21 * * test $(date +\%u) -eq 5 && echo "3rd friday" && Extract_Param.sh /landing/file/ABC/file.txt 
1

Unfortunately, when you give both a day-of-month and a day-of-week in a crontab entry, this means either one is sufficient. (Didn't know that either, but the manpage says so.) This means we can't simply calculate that the 3rd friday is a friday that is between the 15th and 21st of the month.

Fortunately, the above-linked man page also advises us:

One can, however, achieve the desired result by adding a test to the command (see the last example in EXAMPLE CRON FILE below).

[…]

# Run on every second Saturday of the month
0 4 8-14 * *    test $(date +\%u) -eq 6 && echo "2nd Saturday"

so you should be fine with

0 1 15-21 * *    test $(date +\%u) -eq 5 && echo "3rd friday"
| improve this answer | |
  • So this is how i put the entry as i am passing an argument to ithe script i have to schedule? 0 1 15-21 * * test $(date +\%u) -eq 5 && echo "3rd friday" && Extract_Param.sh /landing/file/ABC/file.txt – user3901666 Aug 16 '19 at 7:14
  • Can you please tell me if there is any error in the cron entry? – user3901666 Aug 16 '19 at 9:51
  • @user3901666: well, you should leave off the && echo "3rd friday", other than that, that looks good. – Ulrich Schwarz Aug 16 '19 at 12:34
  • But, I was able to get the cron run with your command , I just had to add a sh before the script. Thank you so much. – user3901666 Aug 16 '19 at 13:34
  • 1
    @user3901666: Yes, the first (day-of-week) of the month will always be in days 1-7, because day 8 is the same as day 1. 8-14 are the second occurences, 15-21 the third, 22-28 the fourth. – Ulrich Schwarz Aug 19 '19 at 6:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.