0

I am facing issue with running a script through snmpwalk command which should redirect a random number into a output file:

I have configured OID for script in snmpd.conf undet /etc/snmp/ as exec .1.3.6.1.4.1.99.1.53.1006 script.sh.sh /root/my_folder/script.sh


My script is as :

#!/usr/bin/ksh 

Out_Path="$HOME/output.txt" 

echo $RANDOM >> $Out_Path
--------------------------

Now i am executing snmpwalk command as : snmpwalk -t 10 -v 1 -c public 127.0.0.1.1.3.6.1.4.1.99.1.53.1006 and in output file i am getting 2 random number instead of 1. I am expecting only one Random number should be present in output.txt file. Can any one explain the behavior or some solution ?


Actual Problem :

I am explaining what i want to achieve.I need to execute a script through snmpget command.

Problem 1: When i use SNMPGET command then script executes and the response (internally) i am getting full (more than 1 KB) but after saving this response in a file i am doing echo $line in a while loop which will take the line of a file and as pes my expectation it should show me the whole data.(But i am able to fetch only 1 KB data )

Problem 2: To solve problem 1 i adopt a new design which is like from 1 OID(script) i got whole data in a file.After that i am executing a new script using new OID which will fetch 1 Record(1KB) and modify the existing data and update the data.So like this i will execute second script multiple time using snmpwalk with different OID so i will get all the record.But my problem is when i am trying to update the reord(file) then in one exection it is removing 2 KB data,because of this reason i posted the question.(2 times random number in 1 snmpwalk command).

I hope you understand the problem now but if you want some more details i will explain you.

Astro - Amit
  • 767
  • 3
  • 15
  • 36
  • This script will accumulate random numbers in the file (`>>` appends the line to the file contents, it's convenient for logs, whereas `>` opens a file from scratch), is it the behavior you need? – Dmytro Sirenko Dec 12 '12 at 12:49
  • @EarlGray : I need that if i will execute snmpwalk command once then only one record Random number must be present in the output file.(echo $RANDOM > $Out_Path) will again redirecting 2 record instead of 1.But i need only one random number by executing snmpwalk command – Astro - Amit Dec 12 '12 at 13:11
  • The snmpwalk command consists of snmpgetnext commands repeated as long as there is something to be returned in a subtree. I suppose in that case two getnext requests are being sent behind single snmpwalk invocation to determine that there is no more data for retrieval. To be sure, please sniffer the traffic using tcpdump or some wireshark solution. Btw. are you sure that -t10 is a right timeout? I would set explicit repetition option to 0 to avoid retransmissions (-r0 option). – lucassm Dec 17 '12 at 08:04
  • @lucassm : You are 100% right the reason is same as you said.Can you please write down the whole command with the above option so i can execute the same.So how can i get the one record.My actual problem is i have data which i have to get through snmp but when i am using snmpget command i am able to get only 1 KB data not more that, so it it possible that i can get more than 1 KB data grom snmp get?Due to this 1 KB problem i disigned a new thing which will be the combination of snmpwalk commands but in that i am facing the problem which i asked here. – Astro - Amit Dec 19 '12 at 04:07
  • 1
    Ok, correct me if I'm wrong. What you are trying to do is to perform snmp get/getnext request on OID you mentioned above to execute a script and return its output as SNMP response. I think that 1 KB problem is caused by something else - it does not seem to be SNMP agent problem in building big responses. Please try following SNMPv1 command (if you have SNMPv3 access as well, please let me know): snmpget -v1 -r0 -cprivate or snmpgetnext -v1 -r0 -cprivate .1.3.6.1.4.1.99.1.53.1005. Please note 1005 octet at the end. Such OID may not exist, getnext shall access 1006 correctly. – lucassm Dec 19 '12 at 12:01
  • Ups, I forgot to add timeout option, which may be required here as default timeout is 5 seconds. So the full command is: snmpget -v1 -t25 -r0 -cprivate or snmpgetnext -v1 -t25 -r0 -cprivate .1.3.6.1.4.1.99.1.53.1005 - let me know about the results. Cheers. – lucassm Dec 19 '12 at 12:11
  • Copy-pasting my comments as response to make text more readable. – lucassm Dec 19 '12 at 12:16

1 Answers1

0

The snmpwalk command consists of snmpgetnext commands repeated as long as there is something to be returned in a subtree. I suppose in that case two getnext requests are being sent behind single snmpwalk invocation to determine that there is no more data for retrieval. To be sure, please sniffer the traffic using tcpdump or some wireshark solution. Btw. are you sure that -t10 is a right timeout? I would set explicit repetition option to 0 to avoid retransmissions (-r0 option).

What you are trying to do is to perform snmp get/getnext request on OID you mentioned above to execute a script and return its output as SNMP response. I think that 1 KB problem is caused by something else - it does not seem to be SNMP agent problem in building big responses. Please try following SNMPv1 command (if you have SNMPv3 access as well, please let me know):

snmpget -v1 -t25 -r0 -cprivate <IP> .1.3.6.1.4.1.99.1.53.1006

or

snmpgetnext -v1 -t25 -r0 -cprivate <IP> .1.3.6.1.4.1.99.1.53.1005

Please note 1005 octet at the OID's end for snmpgetnext request. Such OID may not exist, getnext shall access 1006 correctly as it is first, existing OID after 1005.

lucassm
  • 319
  • 1
  • 6
  • I don't think that you should go into solution described as problem 2. It is to much complex for such simple case. From your OID it seems that this is a column in some table (this is not a scalar, right?). To avoid 1KB limit you encounter I suggest to design separate MIB table, with single column 'data' and index defined as Integer32. Numbers of row in that table could vary depending on script's output size and be indexed like .1 - first line of output (or first some number of bytes < 1KB), and so on. To fill that table you may provide a scalar MIB object just to triger script execution. – lucassm Dec 19 '12 at 15:55
  • So, first you perform a set-request on scalar object and sets its values to some predefined Textual-Convention value (like activate(1)) and after this you perform snmpwalk on table to retrieve i.e. line-by-line or few lines-by-few lines of output. Each row has to return below 1 KB of output. Any further questions? – lucassm Dec 19 '12 at 15:57
  • For above mentioned suggestion i dont have any idea about mib creation and modification and how to write MIB.I know that **/usr/share/snmp/mibs** is the loaction for MIB where all MIB's are present ,and to configure i know **snmpd.conf** file present under **/etc/snmp/** ...so can you please explain in the easy way? – Astro - Amit Dec 19 '12 at 16:10