Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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=0a=`date | cut -c 1-3`
ifa=fri
then"Send mail" | mail -s "remember to bring" $i
i=`expr $i + 1`
else
echo "its not fri"
[ $i -lt 3 ]
fi

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

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/122. 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

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

#!/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

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!

![]() |
![]() |
![]() |

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