|
|
Question : bash script email handling
|
|
How can bash shell script look into the file with following format
login name: real name: bithdate
compare the bithdate with the system date and if they match - sends the email to the relevant user at 1:00 a.m. every day
I tried every possible search to get a hint without any result. Thanks
|
Answer : bash script email handling
|
|
Tyr this:
#!/bin/bash # send_bd_email.sh # # Assuming the birthdate format is: MMDD # CURDT=$(date +%m%d) MSG1=/tmp/msg$$.tmp while read line do nm=$(echo $line| cut -d: -f2|cut -f1) bd=$(echo $line| cut -d: -f3) email=$(echo $line| cut -d: -f1) if test $CURDT -eq $bd then { echo "subject: Happy Birthday!" echo "$nm we wish you the best on your birthday!!" } >$MSG1 mail -tw $email <$MSG1 fi done rm $MSG1 exit #--------------------------------------------------------------------- And add the following line to your crontab:
* 1 * * * /script_path/send_bd_email.sh
|
|
|
|