How many times your server rebooted.? Track your server reboot - Redhat Linux RHCE


You don't know when a server rebooted, when your not there in work place, some times monitoring systems also will not detect the server reboot due to monitoring interval is more. 

 You can track your server reboot as immediate as your server rebooted you will receive an Email alert. How to configure that go through the below easy steps you can configure.


Create an empty file 
~]#touch /var/lock/subsys/SysAlert
~]#vi /etc/init.d/SysAlert

copy the below content to /etc/init.d/SysAlert file


############ Content Start ###############
#!/bin/sh
## Purpose: When your Server Rebooted / Shutdown / Started you will receive an Email alert
## Author: Ravi Kumar
## Date: 04-Sep-2015

#Mail list
MAILLIST="YOUREMAILADDRESS@DOMAINNAME.COM,YOUREMAILADDRESS1@DOMAINNAME.COM"

RESTARTSUBJECT="ALERT! PRODUCTION SERVER ["`SERVERname`"] - System is STARTING UP"
SHUTDOWNSUBJECT="WARNING! PRODUCTION SERVER ["`SERVERname`"] - System is SHUTTING DOWN"

RESTARTBODY="PRODUCTION SERVER "`SERVERname`" has RESTARTED SUCCESSFULLY.
Start up Date and Time: "`date`

SHUTDOWNBODY="WARNING! PRODUCTION SERVER "`SERVERname`" is REBOOTING or SHUTTING DOWN.
Shutdown Date and Time: "`date`

LOCKFILE=/var/lock/subsys/SysAlert
RETVAL=0

# Source function library.
. /etc/init.d/functions

stop()
{
echo -n $"Sending Shutdown Email: "
echo "${SHUTDOWNBODY}" | mail -s "${SHUTDOWNSUBJECT}" ${MAILLIST}
sendmail -q
RETVAL=$?
if [ ${RETVAL} -eq 0 ]; then
rm -f $LOCKFILE
success
else
failure
fi
echo
return ${RETVAL}
}

start()
{
echo -n $"Sending Startup Email: "
echo "${RESTARTBODY}" | mail -s "${RESTARTSUBJECT}" ${MAILLIST}
RETVAL=$?
if [ ${RETVAL} -eq 0 ]; then
touch $LOCKFILE
success
else
failure
fi
echo
return ${RETVAL}
}
case $1 in
stop)
stop
;;
start)
start
;;
*)
esac
exit ${RETVAL}


########### Content END ##################

set the permission to do not modified by other users
 ~]#chown -R root:root /etc/init.d/SysAlert
~]#chkconfig --levels 35 SysAlert
~]#chkconfig --add SysAlert
~]#chmod u+x /etc/init.d/SysAlert

Enjoy.......

When your Server is rebooted / Shutdown / Started you will receive an Email alert.

Please provide your valuable comments.........