我正在寻找解决两台机器(mA和mB)之间ping的替代方案,并将此报告给Nagios(在mC上)。
我目前的想法是编写一个BASH脚本,它将ping cron作业中的机器,将数据输出到一个文件,然后有另一个BASH脚本,Nagios可以使用它来读取该文件。但这不是最好的/正确的方法吗?
下面是我计划在cron作业中运行的脚本:
#!/bin/bash
if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ] || [ -z "$4" ]
then
echo $0: usage: $0 file? ip? pingcount? deadline?
exit 126
else
FILE=$1
IP=$2
PCOUNT=$3
DLINE=$4
while read line
do
if [[ $line == rtt* ]]
then
#replace forward slash with underscore
line=${line////_}
#replace spaces with underscore
line=${line// /_}
#get the 8 item when splitting string on underscore
#echo $line| cut -d'_' -f 8 >> $FILE #Append
#echo $line| cut -d'_' -f 8 > $FILE #Overwrite
echo $line| cut -d'_' -f 8
fi
done < <(ping $IP -c $PCOUNT -q -w $DLINE) #-q output summary / -w deadline / -c pint count
我想使用跟踪路由,但我想这会产生一个较慢的ping?,有没有其他方法来实现我想要的?
注:我知道Nagios可以直接ping机器,但这不是我想做的,也不会告诉我我想要什么。这也是我的第二个剧本,所以可能是垃圾。另外,如果ICMP被阻止,我还有什么选择?