2.11.3 Sample script
Assume that you are responsible for managing the printers on your network. Your goal is to write a script that executes the snmptrap command when the printer scheduler goes down. Here is an example script.
#! /bin/sh
#
#
# This script checks to see if the printer scheduler
# (lpshed) is running. This check is performed every
# hour. If the scheduler is not running, the agent
# sends an SNMP trap to the management station.
#
# If a management station receives a trap from a system with
# enterprise equal to .1.3.6.1.4.1.4242, generic-trap equal
# to 6, and the specific trap equal to 2, the management station
# knows that the printer scheduler for that agent-addr is down.
# The agent sends how many hours the lp scheduler has been
# down with the trap.
#
AGENT_ADDRESS=15.6.71.223
MGMT_STATION=flcndmak
hours=0
while true
do
sleep 3600
pid='ps -ef | grep lpsched | grep -v grep |wc -l'
if [$pid -eq 0]
then
hours='expr $hours + 1'
snmptrap -cpublic $MGMT_STATION .1.3.6.1.4.1.4242
$AGENT_ADDRESS 6 2 0 \
.1.3.6.1.4.1.4242.4.2.0 Integer $hours
else
hours=0
fi
done- Important note
-
In AIX, if the snmptrap or systemtrap command is executed as an extension of a shell script or program started from cron or /etc/inittab, the command might fail with the following message:
snmptrap:cannot set locale($LANG="Ja_JP")
If this message is output, in the LC_ALL environment variable, set the language you want to use.
The following shows an example of setting C as the language code for the B shell.
LC_ALL=C export LC_ALL snmptrap flcndmak .1.3.6.1.4.1.4242 15.6.71.223 6 2 0