-   Programming (
-   -   email on 2nd monday and 3rd monday code (

Dafydd 05-22-2012 05:33 PM

email on 2nd monday and 3rd monday code
There is another thread very simular to this and I don't want to hi-jack his thread, With the moderators permission I will start a new one.

To send an email to a membership list on the 2nd and 3rd Tuesday of each month.


whichmonth=$(date | awk -F" " '{print$2}')
if [ $whichmonth = 'Jan' ]; then
elif [ $whichmonth = 'Feb' ]; then
        .....for the rest of the year.

My question is did I do the OR symbol ( || ) right?

thisTues=$(date | awk -F" " '{print$3}')
if [ "$thisTues" = "$SecondTues" ] || [ "$thisTues" = "$ThirdTues" ]; then
        echo "send email";
        cd /home/dave/tffrobot/
        exit 0
        echo "not today";
exit 0

None of the books I have around the house deal with this. Google search ???? What to search for?

Nominal Animal 05-22-2012 07:22 PM

Why on earth would you hardcode the dates?

The problem at hand is "how to find out if today is the second or third Tuesday of the month?".

First, modify the date output to provide the todays date in more useful form:


# Todays day abbreviation and day number, say "Wed 23".
# Use the POSIX locale explicitly, so we get English weekday abbreviations.
today="$(LC_ALL=C LANG=C date '+%a %d')"

if [ "${today%% *}" != "Tue" ]; then
    # It is not Tuesday today.
    exit 0

# Which week of the month is it?
# The integer division ignores the fraction, so (day)/7+1
# yields the week number.
week=$((${today#* } / 7 + 1))

if [ $week -eq 2 ] || [ $week -eq 3 ]; then
    # It is the second or third Tuesday of this month.


Edited to add: :scratch: Uh, wait; which is it, Monday or Tuesday? The title and your text do not match at all.

Dafydd 05-22-2012 09:12 PM

I'll get back later in the week. Seems my FB account has been hacked and I need to secure it again.

In the mean time thanks for the input.

Dafydd 05-23-2012 11:12 PM


Originally Posted by Nominal Animal (Post 4685224)
Why on earth would you hardcode the dates?

Because I am not a coder of any talent. I do a little HTML and a little script and both are mostly cobbled together from something else.

In this case I needed to send a message on the Friday before the last Tuesday of each month. The code for that worked very well. So I started there.

It will be a couple of weeks before I have to use this. Crontab is set to wake up at 18:00 hours every Tuesday.

Thank you very much for the help.

All times are GMT -5. The time now is 06:10 PM.