[Solved] Cron execute program on first wednesday on month

If none of the more specific forums is the right place to ask

[Solved] Cron execute program on first wednesday on month

Postby gaijin » 2017-11-29 12:07

Hello
I want set cron to execute program on first wednesday on month
I try:
Code: Select all
cat /etc/crontab
30 13 1-7 * 3   root    script.sh


but http://cron.schlitt.info say:
2017-12-01 13:30:00
2017-12-02 13:30:00
2017-12-03 13:30:00
2017-12-04 13:30:00
2017-12-05 13:30:00
2017-12-06 13:30:00
2017-12-07 13:30:00
2017-12-13 13:30:00
2017-12-20 13:30:00
2017-12-27 13:30:00

Someone have a idea
Last edited by gaijin on 2017-12-05 08:06, edited 1 time in total.
gaijin
 
Posts: 12
Joined: 2016-11-22 12:08

Re: Cron execute program on first wednesday on month

Postby pylkko » 2017-11-29 12:35

Use a timer.

for example
Code: Select all

OnCalendar=Wed *-*-01..07 12:00:00


Would run every first - seventh day of the month at noon, but only if it is a Wednesday

see more in the manual:
https://manpages.debian.org/stretch/sys ... .5.en.html

You can add how ever many other conditions you want. Also, if the computer is off, it will run first when you turn it back on (if you want, that is. This cannot be done at all with cron). Or have it run on Wednesdays after 13:30 whenever the computer becomes idle.
User avatar
pylkko
 
Posts: 1213
Joined: 2014-11-06 19:02

Re: Cron execute program on first wednesday on month

Postby wizard10000 » 2017-11-29 13:56

Code: Select all
30 9 * * 3 [ `date +\%d` -le 7 ] && /path/to/task/goes/here


This job will only run on Wednesdays and will exit if the Wednesday is not within the first seven days of the month. You can adjust the time, but this one fires off at 9:30am.

Hope this helps -
we see things not as they are, but as we are.
-- anais nin
User avatar
wizard10000
 
Posts: 1224
Joined: 2011-05-09 20:02
Location: everywhere i go, there i am!

Re: Cron execute program on first wednesday on month

Postby gaijin » 2017-12-04 08:46

wizard10000 wrote:
Code: Select all
30 9 * * 3 [ `date +\%d` -le 7 ] && /path/to/task/goes/here


This job will only run on Wednesdays and will exit if the Wednesday is not within the first seven days of the month. You can adjust the time, but this one fires off at 9:30am.

Hope this helps -

Perfectly. A man learns his whole life.
gaijin
 
Posts: 12
Joined: 2016-11-22 12:08


Return to General Questions

Who is online

Users browsing this forum: No registered users and 5 guests

fashionable