2.11.3 スクリプト例
ネットワークに接続されたプリンタのプリンタスケジューラが不調になった場合,snmptrapコマンドを実行します。snmptrapコマンドのスクリプトの例を説明します。定義例を次に示します。
#! /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- 注意事項
-
AIXでcronや/etc/inittabから起動されたシェルスクリプトやプログラムの延長でsnmptrapまたはsystemtrapコマンドを実行した場合,次のようなエラーが出力されて,コマンドが失敗する場合があります。
snmptrap:cannot set locale($LANG="Ja_JP")
この場合,環境変数LC_ALLに使用する言語を設定してください。
使用する言語に’C’を設定する場合のBシェルの例を次に示します。
LC_ALL=C export LC_ALL snmptrap flcndmak .1.3.6.1.4.1.4242 15.6.71.223 6 2 0