How do I send email on shutdown or reboot

1.Create a file name email_reboot.sh with below lines

#!/bin/bash

# This script will send email to specified email address when system is rebooted
echo "Server Started at `date` " | mail -s "Server (`hostname`) with IP (`hostname -i | awk '{print $1}'`) Started " -r fromaddress toaddress1

2.Now create a entry in crontab


crontab -e

@reboot /etc/jobs/email_reboot.sh >> /var/log/email_reboot.log 2>&1

thats it the above cron job will get executed where ever the system is restarted.

Advertisements
This entry was posted in Linux. Bookmark the permalink.

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