you're reading...
Linux Tips and Tricks

Send Mail Using SENDMAIL

Purpose: To send an alert with customized sender and recipient addresses to be used in cron scripts. There are many ways on how to achieve this and here is my way of getting this done.

This is one of our active cron scripts that checks backup path. This is just to present how sendmail is being used. This is named check_backup.sh and save under /usr/local/sbin and it’s being called daily via cron.

CHECK_FILES=`ls -ltr $BACKUP_PATH|tail -5`
HOSTIPADDR=`/sbin/ifconfig eth1 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'`

echo -e "From:$SENDER \nTo:$RECIPIENT \nSubject: Latest Backup Files @ $HOSTIPADDR \n`date` \n \nBackup Location: $BACKUP_PATH \n$CHECK_FILES" | $SENDMAIL_CMD -t

That’s it!



No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s