03-05-2004 02:03 AM
only on the first weekend of the month with
saturday and sunday being in that month, not
split. And starting on saturday. Don't think
it can be done with cron.
The following crontab entry runs on the 1st
thru the 7th and "also" on saturday not "if"
it is saturday within the 1st - 7th day of the
0 0 1-7 * 6
Solved! Go to Solution.
03-05-2004 02:24 AM
You need to set the job to run on the saturday, then have logic within the script to test if the day is in the first seven days of the month
if [ $DATE_DAY -le 7 ]
This checks if the current day is less than or equal to 7, and runs the code in the if statement.
03-05-2004 02:26 AM
Do you see what I mean?
03-05-2004 02:29 AM
A. Clay Stephenson has some great utilities that help you figure that out. caljd.sh is on http://www.hpux.ws/merijn
I'm attaching a slightly out of date copy.
Owner of ISN Corporation
03-05-2004 02:38 AM
It cannot be done by default with cron. However, you can add that logic into your script to see if this day is first saturday and exit if not. Attached is a script that is to be prefixed to your orignal script. This checks if today is the day you specified via arguments. For ex.,
$./croncheck.sh 1 2
Usage ./ck.cron: Week Weekday
Example: ./ck.cron 1 Fri - for first friday
Your schedule is error
$./croncheck 1 sat
Your schedule is notok
$./croncheck 1 fri
Your schedule is ok
Edit the script and put exit instead of echoing MYSCHEDULE>
Run the whole script (this script + your script) on every saturday with the arguments 'croncheck 1 sat'. It will exit on all other saturdays except first saturday.
03-05-2004 02:48 AM
Actually, you probably want this to run at 00:00 SUNDAY rather than Saturday if I understand your question.
I would change your crontab entry to:
0 0 * * 0
and then add this to your cronjob script. Make sure that PATH is set and exported because cron's environment is intentionally sparse.
I think I understand your question. You require that BOTH Saturday and Sunday be the first instance in this month. If Sunday is the 1st Sunday of the current month but Saturday is the last Saturday of the prior month, you do not want to trigger any action.
Caljd.sh -N's output indicates the occurrance of a current weekday withing the month (1 = 1st; 2 = 2nd; ...)
This should be added in your cronjob script:
if [[ $(caljd.sh -N) -eq 1 && $(caljd.sh -N -p 1) -eq 1 ]]
echo "Do your thing"
echo "Exit; do nothing"
We are checking the occurance of today's weekday (-N) and also the occurance of the previous day (-N -p 1). Only if both equal 1 do we proceed.
Invoke as caljd.sh -u for full usage.