1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
|
#!/bin/bash
# UP script -- WWH -- created
# On start: send SNMP trap ColdStart (0) to TRAPHOST
# On stop: send SNMP trap Enterprise (0) to TRAPHOST
#
# chkconfig: - 99 99
# description: Last thing to be run when system started, first when stopped
#
# processname:
# config:
#
# Notes:
# 1) This generates a BOOT record in $LOGFILE each time the
# system is booted. This boot record consists of the
# uname -a information (see man uname), and the date.
# 2) This also generates SNMP traps when started/stopped:
# start: snmp ColdStart(0) trap to $TRAPHOST
# stop: snmp Enterprise(0) trap to $TRAPHOST
# 3) The name of this is aaaup, but this really should
# get a better name....
# 4) This should be linked to the following in /etc/rc.d/init.d:
# cd /etc/rc.d/rc0.d
# ln -s ../init.d/aaaup K01aaaup
# cd /etc/rc.d/rc1.d
# ln -s ../init.d/aaaup S99aaaup
# cd /etc/rc.d/rc2.d
# ln -s ../init.d/aaaup S99aaaup
# cd /etc/rc.d/rc3.d
# ln -s ../init.d/aaaup S99aaaup
# cd /etc/rc.d/rc4.d
# ln -s ../init.d/aaaup S99aaaup
# cd /etc/rc.d/rc5.d
# ln -s ../init.d/aaaup S99aaaup
# cd /etc/rc.d/rc6.d
# ln -s ../init.d/aaaup K01aaaup
#
# 5) Configuration items are below, but really should be in
# a file like /etc/conf.aaaup:
# Setup variables:
# A) TRAPHOST -- host to send snmptraps to (see man snmptrapd)
#TRAPHOST=yourhost.yourdomain
TRAPHOST=localhost
# B) LOGFILE -- file to log boots/shutdowns....
# typically /var/log/bootlog.txt
LOGFILE=/var/log/bootlog.txt
# C) LOCKFILE -- where the lock for this item should go
# typically /var/lock/subsys/aaaup
LOCKFILE=/var/lock/subsys/aaaup
# D) TRAPPGM -- program/script to generate the trap
# typically /usr/bin/snmptrap
TRAPPGM=/usr/bin/snmptrap
# Set some variables for information reporting....
BOOTDATE=`date`
UNAME=`uname -a`
HNAME=`hostname`
# source function library
. /etc/rc.d/init.d/functions
case "$1" in
start)
echo -n "Starting System: "
cat >>$LOGFILE <<EOF
$BOOTDATE System started
$UNAME
EOF
$TRAPPGM $TRAPHOST public 0 0 "$HNAME restart $BOOTDATE"
touch $LOCKFILE
echo
;;
stop)
echo -n "Stopping System: "
cat >>$LOGFILE <<EOF
$BOOTDATE System shutdown
$UNAME
EOF
$TRAPPGM $TRAPHOST public 6 0 "$HNAME shutdown $BOOTDATE"
rm -f $LOCKFILE
echo
;;
restart)
$0 stop
$0 start
;;
status)
if [ -f $LOCKFILE ]
then
echo "UP -- $HNAME UP, sending traps to $TRAPHOST"
else
echo "DOWN -- $HNAME DOWN, sending traps to $TRAPHOST"
fi
;;
*)
echo "Usage: aaaup {start|stop|restart|status}"
exit 1
esac
exit 0
|