Operating System - Linux
1753265 Members
5619 Online
108792 Solutions
New Discussion юеВ

i need run one command >> file(CRON) on every 1st monday of every month.

 
SOLVED
Go to solution
AA786
Frequent Advisor

i need run one command >> file(CRON) on every 1st monday of every month.

HI,
i need run one command >> file on every 1st monday of every month.

pls help me to write script to verify its 1st monday and then to the crontab entry!!

Please advice if any solution.
2 REPLIES 2
SJO EGGER
Regular Advisor
Solution

Re: i need run one command >> file(CRON) on every 1st monday of every month.

maybe it help├В┬┤s ....

Specific day in a given week

Another common request is to run a command only on a particular day in a particular day of the month. For example, you might want to run a report on the first Monday of each month, or the last Friday. To achieve this, you can use a similar process to the one above. For any particular day in a given week, it must fall within one of the following dates:

Week 1: 1st to the 7th
Week 2: 8th to the 14th
Week 3: 15th to the 21st
Week 4: 22nd to the 28th
To determine whether the current date is within a given range, for example, the fourth week, you would use a test like this:

[ `date +\%e` -gt 21 -a `date +\%e` -lt 29 ]



The %e is used to return a number for the day, where numbers less than 10 are prefixed with a space, rather than a zero, which ensures that numbers, not strings, are compared.

You can now combine this with a crontab definition that attempts to run the command every Friday:

59 23 * * 5 [ `date +\%e` -gt 21 -a `date +\%e` -lt 29 ]
&& do-something



The command will be run every Friday, but because the test will only return true in the fourth week of the month, the real command will be executed on the fourth Friday.
Steven E. Protter
Exalted Contributor

Re: i need run one command >> file(CRON) on every 1st monday of every month.

Shalom,

Use an add in tool in the script which runs every Monday but only does real work the first Monday of the month.

http://mirrors.develooper.com/hpux/caljd-2.25.sh

http://mirrors.develooper.com/hpux/caljd-2.2.pl

These toys will let you do fun things with dates. You may need to change the shell in the first one.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com