Scripts to send notification when an instance fails

eps: Please note this script will most likely send you notification to your spam message. This script should send
emails to you when an ECS instance fails
1) apt-get install bsd-mailx -y (that will install mailx)
2) vi /etc/init.d/emailstartstop
3) paste the content of the script into the above file.
4) chmod 755 /etc/init.d/emailstartstop
5) chkconfig --level 34561 emailstartstop on
7) service emailstartstop start && service emailstartstop stop to test.

The script is as follows:

#!/bin/bash
#
# emailstartstop Send an email on server startup and shutdown.
#
# chkconfig: 2345 99 01
# description: Send an email on server startup and shutdown.

EMAIL="youremail@gmail.com"
STARTSUBJ=`hostname`" started on "`date`
STARTBODY="Just letting you know that server "`hostname`" has started on "`date`
STOPSUBJ=`hostname`" shutdown on "`date`
STOPBODY="Just letting you know that server "`hostname`" has shutdown on "`date`
lockfile=/var/lock/subsys/emailstartstop

# Send email on startup
start() {
echo -n $"Sending email on startup: "

echo "" | mailx -s ""
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch $lockfile
return 0
}

# Send email on shutdown
stop() {
echo -n "Sending email on shutdown: "

echo "" | mailx -s ""
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f $lockfile
return 0
}

# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
*)
echo $"Usage: $prog {start|stop}"
exit 2
esac
exit

Let me know if you have any further question.


Lloyd J.
Amazon Web Services
======================================= 

Comments

Popular posts from this blog

Push command for NetWorker Client Upgrade

Factors Affecting Users’ Sense of Security and Trust in Integrating Electronic health record to the cloud

Basic Elastic Cloud Storage Troubleshooting Commands