[英]Replace SNMP “Timeout: No Response from <IP_Address>” with Specific Text
I have a script that queries OID details via SNMPWalk, the problem is when the certain IP (example is 172.20.36.8) is not reachable, it displays Timeout: No Response from 172.20.36.8
. 我有一个通过SNMPWalk查询OID详细信息的脚本,问题是当某个IP(例如172.20.36.8)无法访问时,它显示
Timeout: No Response from 172.20.36.8
。 Is there a code that could replace that response from snmp query so that if it displays like that, I would like to appear the word "Idle" instead of that "Timeout:..." 是否有代码可以替换来自snmp查询的响应,以便如果这样显示,我希望显示单词“ Idle”而不是“ Timeout:...”
here is the part of the script that I am running: 这是我正在运行的脚本的一部分:
for EACH in `echo $APIP`
do
SectorID=`$SNMPWALK -v2c -c Canopy ${EACH} ${SNMPOID}.1.1.16 | awk '{print $4}'
ActiveSubs=`$SNMPWALK -v2c -c Canopy ${EACH} ${SNMPOID}.1.7.1 | awk '{print $4}'
UniqueSubs=`$SNMPWALK -v2c -c Canopy ${EACH} ${SNMPOID}.1.7.18 | awk '{print $4}'
printf "%s\t| %s\t| %s\t| %s\t|\n" "${EACH}" "${SectorID}" "${ActiveSubs}" "${UniqueSubs}"
done
Now here is the result of the said part of script 现在这是脚本所说部分的结果
172.20.36.3 | 1 | 2 | 4 |
172.20.36.4 | 2 | 5 | 8 |
172.20.36.5 | 3 | 11 | 16 |
Timeout: No Response from 172.20.36.6
Timeout: No Response from 172.20.36.6
Timeout: No Response from 172.20.36.6
172.20.36.6 | | | 0 |
172.20.36.7 | 5 | 0 | 1 |
Timeout: No Response from 172.20.36.8
Timeout: No Response from 172.20.36.8
Timeout: No Response from 172.20.36.8
172.20.36.8 | | | 0 |
when it reaches the ip address .6
and .8
, it displays "Timeout: No Response..."
. 当到达IP地址
.6
和.8
,显示"Timeout: No Response..."
。 I wanted somehow to display it like this if it encounters no response from the said ip address: 我想要以某种方式显示它,如果它没有收到来自所述IP地址的响应:
172.20.36.3 | 1 | 2 | 4 |
172.20.36.4 | 2 | 5 | 8 |
172.20.36.5 | 3 | 11 | 16 |
172.20.36.6 | Idle | Idle | Idle |
172.20.36.7 | 5 | 0 | 1 |
172.20.36.8 | Idle | Idle | Idle |
can anyone out there that can help me to resolve this? 谁能帮助我解决这个问题? I greatly appreciate your responses.
非常感谢您的回复。 :)
:)
You should be able to do something like this: 您应该能够执行以下操作:
SectorID=`$SNMPWALK -v2c -c Canopy ${EACH} ${SNMPOID}.1.1.16 2>&1 | sed 's/Timeout: No Response.*/Idle/'`
if [ "$SectorId" != "Idle" ] ; then
SectorID=`echo $SectorID | awk '{ print $4 }'`
fi
But, the complexity of that script is growing rapidly and I'd be much more tempted to rewrite it in a better scripting environment than sh (I'm not bashing bash; I use it all the time) like python or perl. 但是,该脚本的复杂性正在迅速增长,与在python或perl之类的sh(我不扑bash;我一直在使用它)相比,我更倾向于在一个更好的脚本环境中重写它。 But if you want to use *sh, I'd at least implement a function to do the processing for you once rather than repeating the above 4 times.
但是,如果要使用* sh,我至少要实现一个函数来为您执行一次处理,而不是重复上述4次。 But I'll leave that as an exercise for the reader.
但我会将其留给读者练习。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.