2

I am wondering if this is even possible. I would like my job to start running daily on the 5th business day until the end of the month, every month.

ex Aug - 7-31 Sep - 7-30 Oct - 4-31

Is this even possible?

Thanks in advance

Mindbender
  • 41
  • 1
  • 6
  • 1
    I don't think `cron` has that capability. It's too complex, as months obv can start at any dow. I'd just run it at every `dow=1-5` and put a `return`/`exit` in your job if the time is below the first 5 days, where you likely have a language capable of checking that. – Tobias K. Sep 05 '18 at 18:00

1 Answers1

0

You can use this in your cron tab

* 10 5-31 * * [ "$(date '+\%a')" == "Mon" ] && command to execute
* 10 5-31 * * [ "$(date '+\%a')" == "Tue" ] && command to execute
* 10 5-31 * * [ "$(date '+\%a')" == "Wed" ] && command to execute
* 10 5-31 * * [ "$(date '+\%a')" == "Thu" ] && command to execute
* 10 5-31 * * [ "$(date '+\%a')" == "Fri" ] && command to execute

This will run everyday from 5th of every month till the end of the month at 10 A.M. If it is a weekday. This takes care of the weekdays and not the business calendar.

If you need it to be according to your business calendar you will have to write single a cron for each day it is to be run.

Ref: https://www.switchplane.com/blog/how-to-run-a-cron-job-on-the-first-weekday-of-the-month/

ArnavRay
  • 321
  • 1
  • 9
  • this is a great start ...thank you......Is there a way to make it the 5th business day..for example this month the 5th business day would actually be the 7th. – Mindbender Sep 05 '18 at 19:30
  • I see this other post as well but I cannot figure out the looper and how to get it into the main script [link]https://stackoverflow.com/questions/2516811/in-vb-calculating-the-5th-working-day-of-every-month – Mindbender Sep 05 '18 at 19:30
  • One solution that comes to mind is to write a script probably in python that syncs to the business calendar and runs the required commands if it falls within the date bracket. The python script can be ran on the crontab. The question is quite interesting. I will update if I find a better solution. – ArnavRay Sep 05 '18 at 19:40