View previous topic :: View next topic |
Author |
Message |
dliefbroer n00b
Joined: 10 Feb 2003 Posts: 18
|
Posted: Sat May 31, 2003 1:39 pm Post subject: Notification script for IP and reason for booting |
|
|
I administer a server that, when powered down for a day or 2, receives a new ip adres by DHCP.
Some times there a power failure or something in the weekends so the server won't be restarted for the next monday...
I created this script as an init script: When shutdown the server leaves a file in /etc/ and reboots. When it starts it reads this file to determine if the reboot was intentional an posts the ip adres of the machine as reported by the dyndns service. I'm thinking of just reading ifconfig, but then it won't work for NAT'ed machines
Code: | #!/sbin/runscript
depend() {
need net
}
stop() {
touch /etc/normalshutdown
}
start() {
CURIP=`wget -q -O - checkip.dyndns.org | grep 'IP Address' | awk '{ print $4 }'`
eend $? "External Access Failed"
ebegin "Mailing Administrator about power up"
echo To: ${ADMIN_EMAIL} >> /tmp/tmpnotify
echo Subject: Server Start up >> /tmp/tmpnotify
echo >> /tmp/tmpnotify
if [ -f /etc/normalshutdown ] ; then
rm /etc/normalshutdown
echo "The system was halted as requested" >> /tmp/tmpnotify
else
echo "The system rebooted without the proper commands" >> /tmp/tmpnotify
fi
echo The servers ip adress is now: >> /tmp/tmpnotify
echo $CURIP >> /tmp/tmpnotify
cat /tmp/tmpnotify | sendmail -F"`hostname` Reboot" ${ADMIN_EMAIL}
eend $? "Sendmail Failed"
rm /tmp/tmpnotify
}
|
I called the script /etc/init.d/notify and then just throw a rc-update add notify default.
Enhancement tips are appreciated _________________ LINUX - Because rebooting is for adding new hardware |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|