1753862 Members
7516 Online
108809 Solutions
New Discussion юеВ

Re: Easter Date?

 
SOLVED
Go to solution
A. Clay Stephenson
Acclaimed Contributor

Re: Easter Date?

Okay, I'll assume that you can make a cron entry. I would let your cron entry run every Monday and let the script itself decide if this is one of the 2 "magic" Mondays. That will be defined as those less <= 14 days before Easter but > 0. The firest thing to do is modify the previous easter.sh program to output MM DD YYYY and then it becomes a simple date calculation problem. Hmmm, I wonder what tool to use for that?

Your cron script should look something like this:

#!/usr/bin/sh

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

typeset -i STAT=0
typeset -i EDAYS=$(( $(caljd.sh $(easter.sh)) - $(caljd.sh) ))
if [[ ${EDAYS} <= 14 && ${EDAYS} -ge 0 ]]
then
echo "Do your thing"
# set STAT to a valid value for return
fi
exit ${STAT}

Here is the revised easter.sh that also outputs the year expected by caljd.sh.

If it ain't broke, I can fix that.
A. Clay Stephenson
Acclaimed Contributor

Re: Easter Date?

And here is the other piece, caljd.sh. Invoke as caljd.sh -u for full usage.

If it ain't broke, I can fix that.
A. Clay Stephenson
Acclaimed Contributor

Re: Easter Date?

I did assume that you wanted a completely automatic method so that you would not have to lookup easter each year and could just maintain a list of users (preferably from a file or simple a mail alias.).
If it ain't broke, I can fix that.
A. Clay Stephenson
Acclaimed Contributor

Re: Easter Date?

Ooops, I'm an idiot. I zigged when I should have zagged.

if [[ ${EDAYS} <= 14 && ${EDAYS} -ge 0 ]]

SHOULD BE:
if [[ ${EDAYS} -le 14 && ${EDAYS} -ge 0 ]]

No points for this stupidity please.
If it ain't broke, I can fix that.
James R. Ferguson
Acclaimed Contributor

Re: Easter Date?

Hi (again) Ryan:

Actually, so you don't get every Monday, unconditionally, change my crontab line to be:

0 8 3,10 4 * mailx -s "Easter is April 16" root < /dev/null

Now you will get a mail on April 3 and April 10 announcing the pending Easter.

Regards!

...JRF...
Ryan Clerk
Frequent Advisor

Re: Easter Date?

Hi James and A. Clay,

Thanks for the very quick answers. I'll study these and decide which one to use.

Thanks,
Ryan
James R. Ferguson
Acclaimed Contributor

Re: Easter Date?

Hi Ryan:

The original Perl script I offered can be embellished slightly. Then, add a small shell wrapper to define the number of days before Easter that you want to generate a mail event.

Cron the shell wrapper to run whenever you want it to run. This could be every day of every year if you choose. The shell wrapper is silent unless Easter is 14-days or less away. As a cron'ed script, un-redirected output is mailed to the initiating user, so you don't have to do anything more than run it.

The Perl script is attached and is called '.easter.pl'. If you run it without an argument the current year is assumed. It's output looks like this:

# ./easter.pl
45 days from now is Easter on 04/16/2006

# ./easter.pl 2007
402 days from now is Easter on 04/08/2007

The shell wrapper to cron looks like this:

#!/usr/bin/sh
RSLT=`/usr/local/bin/easter.pl`
LEFT=`echo ${RSLT} | cut -f1 -d " "`
if [ "${LEFT}" -le 14 ]; then
echo ${RSLT}
fi
exit 0

Regards!

...JRF...
James R. Ferguson
Acclaimed Contributor

Re: Easter Date?

Hi (again) Ryan:

Ooops. Since I'm sure you don't want a notice announcing that Easter has passed; as for instance, on April 17 that Easter was -1 days ago for 2006.

Therefore, cron this shell wrapper:

#!/usr/bin/sh
RSLT=`/usr/local/bin/easter.pl $1`
LEFT=`echo ${RSLT} | cut -f1 -d " "`
if [ "${LEFT}" -ge 0 -a "${LEFT}" -le 14 ]; then
echo ${RSLT}
fi
exit 0

Regards!

...JRF...
A. Clay Stephenson
Acclaimed Contributor

Re: Easter Date?

Absolutely, that was my reason for <= 14 and > 0 because in my script, -days would indicate that we had passwd Easter for the current year.
If it ain't broke, I can fix that.