Computing.Net > Forums > Unix > Variables, cant figure em out

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Variables, cant figure em out

Reply to Message Icon

Name: ntenz
Date: August 15, 2005 at 07:16:54 Pacific
OS: aix
CPU/Ram: 2gb ram
Comment:

hi there
I have a small problem. I have a script which purpose is to send emails. First it have to check what day it is .. if it's friday then go ahead.

The problem is how do i make it pick a certain email one week then, next week pick next email and so on.

#!/bin/ksh


0=blablabla@blabla.dk
1=blabla@bla.dk
2=blabl@blaiii.dk
i=0

a=`date | cut -c 1-3`
if

a=fri
then

"Send mail" | mail -s "remember to bring" $i

i=`expr $i + 1`
else
echo "its not fri"
[ $i -lt 3 ]
fi



Sponsored Link
Ads by Google

Response Number 1
Name: David Perry
Date: August 15, 2005 at 11:30:15 Pacific
Reply:

if [ `date +%w` -eq 5 ] ; then
for user in \
blablabla@blabla.dk \
blabla@bla.dk \
blabl@blaiii.dk ; do
echo "Send Mail" | mail -s "remember to bring" $user
done


0

Response Number 2
Name: Luke Chi
Date: August 15, 2005 at 14:58:03 Pacific
Reply:

The simplified algorithm:

1. create a file called input.txt which has only one line to save the last person who was sent the email on last or this Friday, like:
person_3@aol.com 05/08/12

2. In your script, there will be a mail list, like:
MAIL_LIST="person_1@aol.com person_2@aol.com person_3@aol.com person_4@aol.com"

3. In your script, you need to find the next person to send the email to according to the date.

If the date field in input file equals to the current date, then the email still will be sent to the same person in the MAIL_LIST. If the date field in input file is less to the current date, then the email still will be sent to the next person in the MAIL_LIST.

Luke Chi


0

Response Number 3
Name: ntenz
Date: August 16, 2005 at 02:44:08 Pacific
Reply:

well the problem is that i want to repeat the mailing procedure.

"In your script, you need to find the next person to send the email to according to the date"

I dont have dates .. only week days like friday. Sorry for my bad english. Hope you understand.

at friday

mail person1
next friday
mail person2
next friday
mail person3
next friday
mail person1 (again) ~ loop


0

Response Number 4
Name: Luke Chi
Date: August 16, 2005 at 06:17:02 Pacific
Reply:

#!/bin/sh
#
# $FILE originally is empty, this script will create and maintain it
#
# $FILE contents:
#
# Example #1: (the 1st Friday)
# person_1@aol.com 050819
# person_2@aol.com person_3@aol.com person_4@aol.com person_1@aol.com
#
# Example #2: (the 2nd Friday)
# person_2@aol.com 050826
# person_3@aol.com person_4@aol.com person_1@aol.com person_2@aol.com
#
# Example #3: (the 3rd Friday)
# person_3@aol.com 050902
# person_4@aol.com person_1@aol.com person_2@aol.com person_3@aol.com
#
# Example #4: (the 4th Friday)
# person_4@aol.com 050909
# person_1@aol.com person_2@aol.com person_3@aol.com person_4@aol.com
#
# Example #5: (the 5th Friday)
# person_1@aol.com 050916
# person_2@aol.com person_3@aol.com person_4@aol.com person_1@aol.com

FILE=input.txt

if [ `date +%w` -ne 5 ] ; then
exit
fi

CURR_DATE=`date '+%y%m%d'`

if [ ! -s $FILE ]; then
echo "person_1@aol.com $CURR_DATE" > $FILE
echo "person_2@aol.com person_3@aol.com person_4@aol.com person_1@aol.com" >> $FILE
fi

INDEX=0
cat $FILE | while read LINE
do
INDEX=`expr $INDEX + 1`
if [ $INDEX -eq 1 ]; then
set $LINE
LAST_WHO=$1
LAST_DATE=$2
else
# if you run this program for over one time on Friday, the email
# will be sent to the same person
if [ $LAST_DATE = $CURR_DATE ]; then
TARGET_WHO=$LAST_WHO
# else
# find the next person and update $FILE file
else
set $LINE
TARGET_WHO=$1
shift
echo "$TARGET_WHO $CURR_DATE" > $FILE
echo "$@ $TARGET_WHO" >> $FILE
fi
fi
done

# Now you got the email address of the target person

mailx $TARGET_WHO


Luke Chi


0

Response Number 5
Name: ntenz
Date: August 18, 2005 at 02:08:37 Pacific
Reply:

thx alot Luke Chi it works like a charm! I will "re-enginier" it and figure out bout the differnt things/commands. Wonderfull with all u helpfull ppl!


0

Related Posts

See More



Response Number 6
Name: ntenz
Date: August 18, 2005 at 04:17:16 Pacific
Reply:

thx alot thank god there are ppl around like u guys. It works like a charm!


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Variables, cant figure em out

AWK program www.computing.net/answers/unix/awk-program/5058.html

sed - delete duplicate lines www.computing.net/answers/unix/sed-delete-duplicate-lines/7507.html

solaris 8 and counterstrike server www.computing.net/answers/unix/solaris-8-and-counterstrike-server/2824.html