Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash脚本,允许Nagios报告其他两台Linux机器之间的ping_Linux_Bash_Scripting_Nagios - Fatal编程技术网

Bash脚本,允许Nagios报告其他两台Linux机器之间的ping

Bash脚本,允许Nagios报告其他两台Linux机器之间的ping,linux,bash,scripting,nagios,Linux,Bash,Scripting,Nagios,我正在寻找解决两台机器mA和mB之间ping的替代方案,并在mC上向Nagios报告 我目前的想法是编写一个BASH脚本,在cron作业中ping机器,将数据输出到一个文件,然后使用另一个BASH脚本,Nagios可以使用它读取该文件。但这不是最好的/正确的方法 下面是我计划在cron作业中运行的脚本: #!/bin/bash if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ] || [ -z "$4" ] then echo $0: usage:

我正在寻找解决两台机器mA和mB之间ping的替代方案,并在mC上向Nagios报告

我目前的想法是编写一个BASH脚本,在cron作业中ping机器,将数据输出到一个文件,然后使用另一个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被阻止,我会有什么选择?

您是否查看并检查了ping?这将允许nagios机器mC要求mA ping mB,然后mA将结果报告给mC。您需要在mA上安装并配置NRPE和nagios插件,才能使其正常工作。

希望在编写脚本之前我就知道这一点。。。仍然学习bash,这很有趣。