1835055 Members
2381 Online
110073 Solutions
New Discussion

I need a script ..cron

 
SOLVED
Go to solution
claudio_22
Regular Advisor

I need a script ..cron

.. that every 1th Friday on every month run a command ..

Can you help me ?

Thanks
7 REPLIES 7
Pete Randall
Outstanding Contributor
Solution

Re: I need a script ..cron

Set up your crontab entry to run on every friday and then check in your script to see if the day of the month is less than 8.


Pete

Pete
A. Clay Stephenson
Acclaimed Contributor

Re: I need a script ..cron

Have a cron entry run your script every Friday at whatever time you like. You then let the script determine if this is the first, second, ... Friday of the month and either execute normally or exit. The attached script will do this nicely and is very easy to modify for any occurence of a weekday with a month.

#!/usr/bin/sh

export PATH=${PATH}:/usr/local/bin

if [[ $(caljd.sh -N) -eq 1 ]]
then
echo "First Friday; do your thing"
else
exit 0
fi

---------------------------
The above example assumes that you installed the attached, caljd.sh, in /usr/local/bin.


If it ain't broke, I can fix that.
Steven E. Protter
Exalted Contributor

Re: I need a script ..cron

I would suggest a regular cron script that uses the following tool:

http://www.hpux.ws/merijn/caljd-2.23.sh

http://www.hpux.ws/merijn/caljd-2.2.pl

These well documented tools will let you decide if its the first friday of the month.

Have cron run the script every friday and a decision within the secript on whether to act based on what friday it is, using the tool of choice above.

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
Fred Ruffet
Honored Contributor

Re: I need a script ..cron

To complete Pete's answer :

. in crontab, line must begin like that
00 12 * * 5 my_command...
(will start every friday at 12:00)

. Your script must start with something like that :
[ ! $(date +%d) -lt 8 ] && exit 0

Regards,

Fred
--

"Reality is just a point of view." (P. K. D.)
Stephen Keane
Honored Contributor

Re: I need a script ..cron

#!/bin/sh

DOM=`date -u +"%d"`

if [ "$DOM" -gt 8 ]
then
# Not first Friday
exit
fi

# Do your stuff
claudio_22
Regular Advisor

Re: I need a script ..cron

Thanks a lot :-)

Bye
claudio_22
Regular Advisor

Re: I need a script ..cron

.