Operating System - HP-UX
1834499 Members
2842 Online
110068 Solutions
New Discussion

Sending mail automatically at system shutdown and after reboot

 
Abdullatif M. Abdulla
Frequent Advisor

Sending mail automatically at system shutdown and after reboot

I am trying to include mail notification when system shutdown and after reboot. My question is which rc files are suitable for that.

Thanks
7 REPLIES 7
Vijaya Kumar_3
Respected Contributor

Re: Sending mail automatically at system shutdown and after reboot

Just have a Script to check /etc/rc.log and uptime information to run in the cron every 5 or 10 minutes.

I think, uptime will be enough for sending email notification.

Just an idea:
Use uptime to check the system uptime. If it is less than 30 minutes send an alert.

Hope this helps
vijay
Known is a drop, unknown is ocean - visit me at http://vijay.theunixplace.com
Vijaya Kumar_3
Respected Contributor

Re: Sending mail automatically at system shutdown and after reboot

I just got you an another idea:

Use the run control file to send you an email. You may add a line to send email notice in the end of /sbin/rc3 file, so that you will receive a mail once the system is rebooted and online.

This idea is better than the previos one.

Hope this helps
Vijay
Known is a drop, unknown is ocean - visit me at http://vijay.theunixplace.com
Sridhar Bhaskarla
Honored Contributor

Re: Sending mail automatically at system shutdown and after reboot

Hi,

You can write one script that will take care of sending mail for both shutdown and after reboot. However, if the system crashes due to any error the shutdown script won't send any mail.

Look at /sbin/init.d/template file on how to write the code. Basicall there should be a case statement with four cases. start - code to run when the system is booting, stop - code to run when the system is going down, start_msg - Message to be displayed at the console when the system is coming up and stop_msg - Message to be displayed when the system is going down. Your script for each of these cases would be simple. Just send a mail with appropriate subject and body.

Once the /sbin/init.d/your_script is created, I would put the links in /sbin/rc3.d and create them like S800myscript and K800myscript. I prefer rc3.d as the mail client you use would invoke sendmail as a client and sendmail won't work nicely if the system is not with appropriate network configuration.

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Abdullatif M. Abdulla
Frequent Advisor

Re: Sending mail automatically at system shutdown and after reboot

Can you help with an example for ~template after adding the following line:
date | mailx -s "Shutdown the system" someone@somwhere.com

When system is up:
date | mailx -s "System up again" someone@somwhere.com


Thanks a lot
Elmar P. Kolkman
Honored Contributor

Re: Sending mail automatically at system shutdown and after reboot

What you need to do is put the shutdown mail in the stop-part of your script and the booted message in the start part of the script. The commands themselves seem correct.
Every problem has at least one solution. Only some solutions are harder to find.
Geoff Wild
Honored Contributor

Re: Sending mail automatically at system shutdown and after reboot

How about this:

Create a script in /sbin/init.d

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

rval=0
set_return () {
x=$?
if [ $x -ne 0 ] ; then
echo "FAILURE CODE: $x"
rval=1
fi
}
case $1 in
start_msg)
echo "Mail server boot status"
;;

stop_msg)
echo "mail server shutdown status"
;;


start)
DATE=`/usr/bin/date`
/usr/bin/mailx -s "Server booted at $DATE" yourid@yourdomain.com ;;
stop)
DATE=`/usr/bin/date`
/usr/bin/mailx -s "Server Shutdown at $DATE" yourid@yourdomain.com ;;
esac
exit 0


Then in /sbin/rc3.d link it:

ln -s ../init.d/servermsg S995servermsg

Then in rc2.d link it:

ln -s ../init.d/servermsg K001servermsg

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.
Dave La Mar
Honored Contributor

Re: Sending mail automatically at system shutdown and after reboot

Please see the attached pdf for creating startup and shutdown scripts. It is straight forward and can be tested ouside the actual condition. Though the os version number may not match it should still provide what you need.

Best of luck.

Regards,

dl
"I'm not dumb. I just have a command of thoroughly useless information."