Friday, June 10, 2005

reboot email script

Hi,
Below a simple script I put in rc2.d to alert me when a machine reboots
Name is S99reboot
------------------------
#!/bin/sh
# just a mail when reboot occurs
mode=$1

if [ ! -d /usr/bin ]
then # /usr not mounted
exit 1
fi

set `/usr/bin/id`
if [ $1 != "uid=0(root)" ]; then
echo "$0: must be run as root"
exit 1
fi
host="`uname -n`"
moi="may mail adress"

case "$mode" in

'start')
echo "Reboot of $host : " `date` | mailx -s $host $moi
;;

'stop')
echo "Stop of $host : " `date` | mailx -s $host $moi
;;

*)
echo " Option unknown"
exit 1
;;
esac

exit 0

0 Comments:

Post a Comment

<< Home