并行处理多个主机

时间:2018-02-27 08:42:48

标签: linux bash

我想使用fping ping parellel中的一些主机,如果有人将其写入文件。以下是工作,但它为每个ip运行一次如何消除这个或如果rcv< 1?

#!/bin/bash

down_hosts=/tmp/down.log
hosts=/tmp/ips.txt

while read line  
do
    alive=$(fping -c 1 -f ips.txt | awk -F: '{ print $1 }')
    grep -q -o $line <<<$alive
    if [[ "$?" ==  "1" ]];
    then
        echo "$line is offline"
        if  [ $(grep -c "$line" "$down_hosts") -eq 0 ]; then
            echo $line >> down.log
        fi    
    else
        echo "$line is online"
        if  [ $(grep -c "$line" "$down_hosts") -eq 1 ]; then
            sed -i "/$line/d" "$down_hosts"
        fi
    fi
done < ips.txt

输出

8.8.8.8 : xmt/rcv/%loss = 1/1/0%, min/avg/max = 3.67/3.67/3.67
1.2.3.4 : xmt/rcv/%loss = 1/0/100%
4.3.2.1 : xmt/rcv/%loss = 1/0/100%
8.8.8.8 is online

8.8.8.8 : xmt/rcv/%loss = 1/1/0%, min/avg/max = 3.68/3.68/3.68
1.2.3.4 : xmt/rcv/%loss = 1/0/100%
4.3.2.1 : xmt/rcv/%loss = 1/0/100%
1.2.3.4 is offline

8.8.8.8 : xmt/rcv/%loss = 1/1/0%, min/avg/max = 3.65/3.65/3.65
1.2.3.4 : xmt/rcv/%loss = 1/0/100%
4.3.2.1 : xmt/rcv/%loss = 1/0/100%
4.3.2.1 is offline

0 个答案:

没有答案