Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Networking
User Name
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.


  Search this Thread
Old 12-12-2008, 12:16 AM   #1
LQ Newbie
Registered: Jul 2008
Posts: 11

Rep: Reputation: 1
NetSnmp exec script return data type

Hello All.

I have question about snmpd exec command.
When executing script from snmpd the returned data is with string type, for example:

This is my config line:
exec . test /bin/bash /home/sam/

this is my output:
UCD-SNMP-MIB::ucdavis.99.1.1 = INTEGER: 1
UCD-SNMP-MIB::ucdavis.99.2.1 = STRING: "test"
UCD-SNMP-MIB::ucdavis.99.3.1 = STRING: "/bin/bash /home/sam/"
UCD-SNMP-MIB::ucdavis.99.100.1 = INTEGER: 0
UCD-SNMP-MIB::ucdavis.99.101.1 = STRING: "100"
UCD-SNMP-MIB::ucdavis.99.102.1 = INTEGER: 0
UCD-SNMP-MIB::ucdavis.99.103.1 = ""

my script is "echo 100"

A question is how to get this value with integer data type or how can i return this data from bash as integer.

For example command "exit 3" from bash return integer 3.
But exit codes is restricted, i can use exit code great then 160 .

Old 01-24-2009, 12:08 PM   #2
LQ Newbie
Registered: Oct 2007
Posts: 4

Rep: Reputation: 0

I have been trying to setup the net-snmp to run a script remotely the same way you have explained, but when configure as you mentioned I cannot get the expected output with snmpwalk.

This is my config line:
exec . test /bin/bash /home/sam/

End of MIB

I wonder whether you can help me with this.

Old 01-24-2009, 10:54 PM   #3
LQ Newbie
Registered: Jul 2008
Posts: 11

Original Poster
Rep: Reputation: 1
Hello cdivitotawela.

Please show your file and the walk command.
Old 01-25-2009, 12:02 PM   #4
LQ Newbie
Registered: Oct 2007
Posts: 4

Rep: Reputation: 0
Hi Hemull,

I have used the example provided in the snmp.conf file itself but the problem same.

1. Entered following line in the /etc/snmp/snmp.conf file
exec . shelltest /bin/bash /tmp/shtest

2. Created the script /tmp/shtest containing following
echo hello world
echo hi there
exit 35

3. Ran following command
/usr/bin/snmpwalk -v 1 localhost -c public .

4. Output as follows
> /usr/bin/snmpwalk -v 1 localhost -c public .
End of MIB

I tried this about 2 years back(older version of net-snmp) and it did work but now with new version and Fedora 7 this doesn't seems to work anymore. I am not sure whether I have missed configuring anything or some additional changes I need to perform in order to make this work. If you can help me with this it will be a great help.

Thank you.

Old 01-25-2009, 10:47 PM   #5
LQ Newbie
Registered: Jul 2008
Posts: 11

Original Poster
Rep: Reputation: 1
Hello cdivitotawela.

Firstable you should to view if this script /tmp/shtest is running when you perform snmp query.
Just insert this line echo "123" >> /tmp/test.log, if file test.log is created so script is running.

Try to use v2 snmp.

Or you can try to use next construction:

pass . /bin/sh /tmp/

2) Check execute permissions of shtest script.
Old 02-01-2009, 10:12 AM   #6
LQ Newbie
Registered: Oct 2007
Posts: 4

Rep: Reputation: 0
Thanks hemulll,

Used the pass also but no result. Script execution rights are 755 so I don't think there is a problem in rights either. In the script I entered a echo to a file and it seem the script is not executed at all. I am really lost here and could not find anyone has got same issue. May be a silly mistake. Need to look for the root cause more.

If you can think of any reasons let me know. Thanks a lot your help in this.

Old 06-18-2009, 04:26 PM   #7
LQ Newbie
Registered: Apr 2006
Location: St. Louis, MO
Distribution: Ubuntu currently, but Fedora is my favorite
Posts: 8

Rep: Reputation: 0
Cannot execute scripts from snmpd.conf file either


I am having the same problem as cdivitotawela. I will attach my conf file. I have two basic scripts I would like to run for proof of concept. One is the simple echotest, and the other is just a testing script to be built on in the future.

rwcommunity public
syslocation "Intern Cube"
syscontact sam@localhost

#exec echotest /bin/echo hello world
exec testing /bin/sh /tmp/test

#these next three lines were just testing to see if the entire extensions 
#was broken, or if it was just the exec command

proc snmpd
proc apache2

disk / 100000
According to the man page the oid preceding it is not necessary, but I've tried it in snmp 1 and 2 and cannot get this to work. Please let me know if you have any ideas. Thanks in advanced,

Old 11-28-2011, 06:51 AM   #8
LQ Newbie
Registered: Nov 2011
Posts: 3

Rep: Reputation: Disabled
Exec only returns string

Hi All,

I have same issue. I wrote sh script and returns number like "4"

I want to get this information via OID in integer type but it returns STRING.

[root@CFSFTZLAL01 ~]# snmpwalk -v 2c -c BooS3wee2ree0zei4kiW localhost SNMPv2-SMI::enterprises.637.334
SNMPv2-SMI::enterprises.637.334.1.1 = INTEGER: 1
SNMPv2-SMI::enterprises.637.334.2.1 = STRING: "perl"
SNMPv2-SMI::enterprises.637.334.3.1 = STRING: "/scripts/"
SNMPv2-SMI::enterprises.637.334.100.1 = INTEGER: 0
SNMPv2-SMI::enterprises.637.334.101.1 = STRING: "60"
SNMPv2-SMI::enterprises.637.334.102.1 = INTEGER: 0
SNMPv2-SMI::enterprises.637.334.103.1 = ""
[root@CFSFTZLAL01 ~]# cat "/scripts/"
$int2 = int(60.13);
print "$int2\n";
[root@CFSFTZLAL01 ~]#

Can you please help me on this issue? How can I get the value as INTEGER type?
Old 11-28-2011, 07:00 AM   #9
LQ Guru
Registered: Apr 2005
Posts: 5,817

Rep: Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002

This thread is OVER TWO YEARS OLD. Please don't thread jack other people's threads too..... Search these forums and online first, and if you can not find an answer to your question, then by all means, create a new thread. Thank you for understanding.




exec, netsnmp

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
no exec permission on my data partition sycamorex Linux - General 14 11-11-2008 05:21 PM
Backing up ~75GB of data on Redhat rel 4 srvr using backup exec shows ~1.3TB of data? unicorntoo Linux - Software 1 05-01-2008 08:32 AM
PHP return type error bahadur Programming 0 08-11-2006 04:37 AM
C++ return type ashirazi Programming 4 09-19-2004 03:01 PM
constructor return type macro-linux Programming 2 11-12-2003 01:29 AM > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 09:07 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration