I am trying to get the uptime of servers using SNMP. First I check if the server is online, then I try to retrieve the uptime. The issue is that I want to run the command multiple times to decrease latency in script, but I am not getting the expected output into the array.
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
The output that I get when running the command outside of the script is:
5:58:27.35
But inside the script I get:
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
Any help would be great. Probably a small issue in the script I have over looked.