Jump to: navigation, search

Setting up a cron job for sending e-mails[edit]

This is the way I implemented it, but there can be other ways..

On your home dir on srv1.tolabaki.gr edit the cron job file

crontab -e

and tell it to run a specific script lets say every Monday of the month at 13:37 by adding this line

37 13 * * 1 reminders/labaki-meeting-2days.sh

where first 5 entries are minute, hour, day of month, month, day of week.

The shell script has the magic. I say magic 'cause for labaki we didn't want it every Monday, but only a specific Monday of the month. Anyway, example is here:

DATE=`date +%d`
MONTH=`date +%m`
MNT = `date -d +2 days +%m`
if [ "$DATE" -lt "7" ]; then
  /usr/sbin/sendmail announce@tolabaki.gr saloni@tolabaki.gr < /abspath/labaki-meeting-2days.txt
        if ["$MNT" -ne "$MONTH"]; then
          /usr/sbin/sendmail announce@tolabaki.gr saloni@tolabaki.gr < /abspath/labaki-meeting-2days.txt 


Skip the ifs for now . Let's just say we want to send the mail. To do this I use sendmail which is already on the server.

The content of the email is stored in the txt file /abspath/labaki-meeting-2days.txt:

Subject: Reminder: Labaki meeting on Thursday!
From: labaki reminder monster <noreply@tolabaki.gr>
To: saloni@tolabaki.gr; announce@tolabaki.gr 

I have materialized into your inbox to inform you that 
The First Thursday Of The Month is in 2 days.
See you @tolabaki then!

Send a test email and you're done :)

More Details: The ifs are for the mail to be sent only on the week of the first Thursday of the month. You might want to check, but I think that the senders in the txt file don't really matter. What is important is that you add them to the line

 /usr/sbin/sendmail announce@tolabaki.gr saloni@tolabaki.gr < /abspath/labaki-meeting-2days.txt