for循环中的并行命令 - Bash

时间:2016-11-13 16:02:15

标签: bash awk snmp

我正在尝试使用SNMP获取服务器的正常运行时间。 首先,我检查服务器是否在线,然后我尝试检索正常运行时间。 问题是我想多次运行该命令以减少脚本中的延迟,但我没有将预期的输出输入到数组中。

for ip in "${Iparray[@]}"
do
    uparray=($(snmpwalk -Os -c public -v 1 $ip DISMAN-EVENT-MIB::sysUpTimeInstance | grep "^sysUpTimeInstance" | awk '{print $5}')) &
done
tail /proc/uptime | grep -o '^\S*'
wait $(jobs -p)
for ti in "${uparray[@]}"
do
    echo $ti
done

在脚本之外运行命令时得到的输出是:

5:58:27.35

但在剧本里面我得到了:

Timeout: No Response from 192.168.0.2
Timeout: No Response from 192.168.0.3    
Timeout: No Response from 192.168.0.5
Timeout: No Response from 192.168.0.4
Timeout: No Response from 192.168.0.1
Timeout: No Response from 192.168.0.6
Timeout: No Response from 192.168.0.12
Timeout: No Response from 192.168.0.14
Timeout: No Response from 192.168.0.13
Timeout: No Response from 192.168.0.10
Timeout: No Response from 192.168.0.21
Timeout: No Response from 192.168.0.24
Timeout: No Response from 192.168.0.22
Timeout: No Response from 192.168.0.101
Timeout: No Response from 192.168.0.23
Timeout: No Response from 192.168.0.254
Timeout: No Response from 192.168.0.107

任何帮助都会很棒。可能是我看过的脚本中的一个小问题。

0 个答案:

没有答案