snmptools issue

Posted by theosan2 on 2016-12-06 14:10

When executing:
> snmp session lo -v1 -t0.1 -c public 192.168.1.254
> set ret [lo get sysDescr.0]
> lo close
Get Output:
SNMPv2-MIB::sysDescr.0 = STRING: SG300-10PP 10-Port Gigabit PoE+ Managed Switch

I can repeat this as many I want it is always correct. Read next why i am stating this

When I source:
proc Go {} {
snmp session lo -v1 -t0.1 -c public 192.168.1.254
set ret [lo get sysDescr.0]
lo close
return $ret
}

and execute:
> Go
SNMPv2-MIB::sysDescr.0 = STRING: SG300-10PP 10-Port Gigabit PoE+ Managed Switch

So far all is fine (you think...)

Now run Go again:
> Go
Timeout: No Response from 192.168.1.254.

WHY...???

Now SOURCE script AGAIN:
proc Go {} {
snmp session lo -v1 -t0.1 -c public 192.168.1.254
set ret [lo get sysDescr.0]
lo close
return $ret
}

> Go
SNMPv2-MIB::sysDescr.0 = STRING: SG300-10PP 10-Port Gigabit PoE+ Managed Switch

It works ONLY correct after SOURCING the script each time...

Can someone help to have the script work without sourcing all the time...