1843997 Members
2259 Online
110226 Solutions
New Discussion

Shutdown Notification

 
SOLVED
Go to solution
AIMC
Frequent Advisor

Shutdown Notification

Hi,

I am wondering if there is a script i can run or a file that can be edited to mail me when a server has been issued a shutdown command?

Regards,

Aidan
7 REPLIES 7
harry d brown jr
Honored Contributor

Re: Shutdown Notification

Sure, put a script into /sbin/rc2.d/ called something like K090notifyme.

live free or die
harry
Live Free or Die
Ken Penland_1
Trusted Contributor

Re: Shutdown Notification

You could add a shutdown script that sends you an email, just put it in /sbin/rc2.d/ and call it K999 as long as it runs before sendmail shuts down, every time the system shuts down it will run that script, sending an email
'
AIMC
Frequent Advisor

Re: Shutdown Notification

Hi Harry,

Could you tell me what needs to be in the script? Also if i have a K090notifyme in rc2.d do i need an S910notify me in rc3.d?

Appoplogies if this is asking too much but I am not a sys admin, just a hardware engineer trying to keep track of expensive test equipment!

Thanks,

Aidan
Robert-Jan Goossens
Honored Contributor

Re: Shutdown Notification

K090

/usr/bin/mailx -s "system xxxx has been shutdown" aidan@foo.com

S910

/usr/bin/mailx -s "system xxxx has been started" aidan@foo.com

regards,
Robert-Jan
Ken Penland_1
Trusted Contributor

Re: Shutdown Notification

the script could be as simple as:

echo `hostname` is rebooting |mailx -s "reboot msg" yourname@company.com
'
harry d brown jr
Honored Contributor
Solution

Re: Shutdown Notification

create a script called "notifyme" in /sbin/init.d:

#!/sbin/sh
#
unset UNIX95
PATH=/sbin:/usr/sbin:/usr/bin
export PATH

NOTIFYLIST="YOUR_EMAILNAME@YOURDOMAIN.com"

case $1 in

start_msg)
echo "Send an email to notifyme that system is being broght backup"
;;

stop_msg)
echo "Send an email to notifyme that system is being shutdown"
;;

start)

echo "System (`hostname`) coming back up"|mailx -s"System `hostname` booting" ${NOTIFYLIST}
;;

stop)
echo "System (`hostname`) going down"|mailx -s"System `hostname` shutting down" ${NOTIFYLIST}
;;

*)
echo "usage: $0 {start|stop}"
;;
esac

exit

Change permissions to execute:
chmod 555 /sbin/init.d/notifyme

Then create TWO symbolic links:

ln -s /sbin/init.d/notifyme /sbin/rc2.d/K090notifyme

ln -s /sbin/init.d/notifyme /sbin/rc2.d/S090notifyme

Then have at it

live free or die
harry
Live Free or Die
Geoff Wild
Honored Contributor

Re: Shutdown Notification

Just anoher less elaborate way - add your name to root's email in /etc/mail/aliases:

root : you@yourdomain.com

then newaliases, and restart sendmail.

You will get email on boot like this:

Subject: Server booted at Fri Jun 11 09:42:57 MDT 2004

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.