Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 05-22-2012, 05:33 PM   #1
Registered: Oct 2008
Posts: 344

Rep: Reputation: 29
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?
Old 05-22-2012, 07:22 PM   #2
Nominal Animal
Senior Member
Registered: Dec 2010
Location: Finland
Distribution: Xubuntu, CentOS, LFS
Posts: 1,723
Blog Entries: 3

Rep: Reputation: 946Reputation: 946Reputation: 946Reputation: 946Reputation: 946Reputation: 946Reputation: 946Reputation: 946
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: Uh, wait; which is it, Monday or Tuesday? The title and your text do not match at all.

Last edited by Nominal Animal; 05-22-2012 at 07:26 PM.
1 members found this post helpful.
Old 05-22-2012, 09:12 PM   #3
Registered: Oct 2008
Posts: 344

Original Poster
Rep: Reputation: 29
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.
Old 05-23-2012, 11:12 PM   #4
Registered: Oct 2008
Posts: 344

Original Poster
Rep: Reputation: 29
Originally Posted by Nominal Animal View Post
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.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Last monday of each month Perl jt1 Programming 4 09-07-2011 03:16 PM
LXer: Funny On Monday - MS Has Pushed It Too Far LXer Syndicated Linux News 0 08-04-2008 04:20 AM
Running a job the first monday of the month? yanik Linux - General 12 03-05-2008 05:08 PM
RHCT Administration Monday! carlosinfl Linux - Certification 4 03-07-2007 01:15 AM
bloody monday aizkorri General 2 05-19-2003 05:45 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:42 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration