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
Post a Comment