How to setup Cron Job on first Monday of every month ?? -Thanks
Printable View
How to setup Cron Job on first Monday of every month ?? -Thanks
first you must have the right to have a crontab, or login as root, then crontab -e (edit), and you add your line :
min hour day_of_month month weekday
to run something every first monday of every month at 8:15, just do :
15 8 1-7 * 1 command
that is to say you'll launch your command every monday that is between the 1st and 7th day of the month, that is to say the first monday ...
Got you. Thx
Anybody got another idea for this? On Solaris, this entry would run at 8:15 on Monday's AND days 1-7.
I guess, crontab entries are "OR"ed.
So, 15 8 1-7 * 1 command will execute the 'command' on all Mondays and first 7 days of a month.
So, unless there is a better way, the 'command' will have to take care of checking that "it really is first Monday of the Month".
This was interesting question so I posted it on unix.com, here is what Perderabo came up with....
This usual solution is something like, first write a wrapper script that will run somecommand only if the day of the month is 7 or less:
code:--------------------------------------------------------------------------------
#! /usr/bin/ksh
day=$(date +%d)
if ((day <= 7)) ; then
exec somecommand
fi
exit 1
--------------------------------------------------------------------------------
Then run the wrapper every Monday: "0 0 * * 1 wrapper".
I was afraid of that. I think the "tacky" police will be hunting me down...
We did same way,
crontab, we scehdule daily base
2 0 * * * myjob
in the shell script:
myjob code---------------------------------------
wkdate=`date +%w`
DD=`date +%d`
# Mon - Fri, & Sun run daily process
# Saturday run weekly process except:
# the 1st Saturday of each month run monthly process
case $wkdate in
6)
if [[ $DD -lt 8 ]] ; then
echo run monthly process
./month_process.sh
else
echo run weekly process
./weekly_process.sh
fi
;;
*)
echo run daily process
./daily_process.sh
;;
esac
----------------------------------------------------