Created
July 4, 2012 07:04
-
-
Save editnuki/3045814 to your computer and use it in GitHub Desktop.
引数を利用してpingの試行回数、ホスト、時間を指定して行う死活監視スクリプト
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
FILE="/home/user/shell/deadscript/ping_result.txt" | |
PACKET_LOSS_FILE="/home/user/shell/deadscript/ping_result_packet_loss.txt" | |
PACKET_TIME_FILE="/home/user/shell/deadscript/ping_result_time.txt" | |
PING_RESULT=`ping -c $1 $2 > $FILE` | |
RESULT_LOSS=`cat $FILE | tail -2 | head -1 | awk '{print $6}' | sed 's/\%//g' > $PACKET_LOSS_FILE` | |
RESULT_TIME=`cat $FILE | tail -2 | head -1 | awk '{print $10}' | sed 's/ms//g' > $PACKET_TIME_FILE` | |
LOSS=`cat $PACKET_LOSS_FILE` | |
TIME=`cat $PACKET_TIME_FILE` | |
RMFILE=`rm -f $FILE` | |
#パケロスが100かどうかで死活監視 | |
if [ $LOSS -lt 100 ];then | |
#パケットロスが100未満でもロス率が50%を超えていたらアラート | |
if [ $LOSS -lt 50 ];then | |
#pingの処理時間で応答確認を行う。第三引数の値よりも高い場合障害 | |
if [ $TIME -lt $3 ];then | |
echo "$2 is OK. time is $TIME ms" | |
else | |
echo "time is too long to $2. time is $TIME ms" | |
fi | |
else | |
echo "PACKET LOSS HIGH! $LOSS % packet loss" | |
fi | |
else | |
echo "$2 is host down or $2 network is Obstruction. $LOSS % packet loss" | |
fi | |
RMPACKET_LOSS_FILE=`rm -f $PACKET_LOSS_FILE` | |
RMPACKET_TIME_FILE=`rm -f $PACKET_TIME_FILE` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
第一引数が試行回数
第二引数が監視先ホスト名
第三引数が応答時間