Tclsh snmp format

578 Views Asked by At

I am trying to get a value from an instance with OID using tcl command.

In TCL, the command works:

% set snmp_result [snmpwalk -Os -c public -v 2c 192.168.1.20 .1.3.6.1.4.1.31926.2.1.1.19]
iso.3.6.1.4.1.31926.2.1.1.19.1 = INTEGER: -57

I am trying to get the number -57 only, so I wrote a tclsh script:

set snmp_result [snmpwalk -Os -c public -v 2c 192.168.1.20 .1.3.6.1.4.1.31926.2.1.1.19]
set splitted_result [split $snmp_result ""]
puts [lindex $splitted_result 3]

And then I got error:

invalid command name "snmpwalk"
    while executing
"snmpwalk -Os -c public -v 2c 192.168.1.20 .1.3.6.1.4.1.31926.2.1.1.19"
    invoked from within
"array set snmp_result [snmpwalk -Os -c public -v 2c 192.168.1.20 .1.3.6.1.4.1.31926.2.1.1.19]"
    (file "./siklu.tcl" line 1)

I also learned that the tclsh is EEM policy, so I tried:

array set snmp_res [sys_reqinfo_snmp -c public -v 2c 192.168.1.20 oid .1.3.6.1.4.1.31926.2.1.1.19 get_type exact]

But that gave me this error:

invalid command name "sys_reqinfo_snmp"
    while executing
"sys_reqinfo_snmp -c public -v 2c 192.168.1.20 oid .1.3.6.1.4.1.31926.2.1.1.19 get_type exact"
    invoked from within
"array set snmp_res [sys_reqinfo_snmp -c public -v 2c 192.168.1.20 oid .1.3.6.1.4.1.31926.2.1.1.19 get_type axact]"
    (file "./siklu.tcl" line 2)
1

There are 1 best solutions below

1
On

You have to use exec command to execute them.

set snmp_result [exec snmpwalk -Os -c public -v 2c 192.168.1.20 .1.3.6.1.4.1.31926.2.1.1.19]
puts $snmp_result