LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices


Reply
  Search this Thread
Old 05-22-2012, 05:33 PM   #1
Dafydd
Member
 
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.

Code:
#!/bin/bash
whichmonth=$(date | awk -F" " '{print$2}')
if [ $whichmonth = 'Jan' ]; then
	SecondTues=07;
	ThirdTues=14;
elif [ $whichmonth = 'Feb' ]; then
	SecondTues=10;
	.......................
	.....for the rest of the year.
fi
My question is did I do the OR symbol ( || ) right?
Code:
thisTues=$(date | awk -F" " '{print$3}')
if [ "$thisTues" = "$SecondTues" ] || [ "$thisTues" = "$ThirdTues" ]; then
	echo "send email";
	cd /home/dave/tffrobot/
	./tuesday-flytying-send.sh
	exit 0
fi
	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: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948
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:
Code:
#!/bin/bash

# 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
fi

# 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.

fi
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
Dafydd
Member
 
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.
Dave/
 
Old 05-23-2012, 11:12 PM   #4
Dafydd
Member
 
Registered: Oct 2008
Posts: 344

Original Poster
Rep: Reputation: 29
Quote:
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.
Dave
 
  


Reply


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

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:46 AM.

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