简体   繁体   English

从外壳程序脚本中获取随机数,然后使用snmpcommad(SNMP协议)将其存储到文件中

[英]Getting a random number from a shell script and store it in to a file using snmpcommad (SNMP Protocol)

I am facing issue with running a script through snmpwalk command which should redirect a random number into a output file: 我在通过snmpwalk命令运行脚本时遇到问题,该脚本应将随机数重定向到输出文件:

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 我已经在snmpd.conf undet / etc / snmp /中将脚本的OID配置为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. 现在,我正在以以下方式执行snmpwalk命令:snmpwalk -t 10 -v 1 -c public 127.0.0.1.1.3.6.1.4.1.99.1.53.1006并且在输出文件中,我得到2个随机数而不是1。我期望只有一个随机数应出现在output.txt文件中。 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. 我正在解释我要实现的目标。我需要通过snmpget命令执行脚本。

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 ) 问题1:当我使用SNMPGET命令时,脚本将执行,并且响应(内部)执行完毕 (超过1 KB),但是将响应保存在文件中后,我将在while循环中执行echo $ line ,这会占用该行一个文件,并且按我的期望,它应该显示整个数据。(但是我只能提取1 KB数据)

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). 问题2:为了解决问题1,我采用了一种新设计,就像从1个OID(script)开始,我将整个数据保存在一个文件中。此后,我正在使用新的OID执行一个新脚本,该脚本将获取1个Record(1KB)并进行修改这样,我将使用具有不同OID的snmpwalk多次执行第二个脚本,因此我将获得所有记录。但是我的问题是,当我尝试更新reord(file)时,一次执行由于这个原因,我正在删除2 KB数据。(在1条snmpwalk命令中,随机数是2倍)。

I hope you understand the problem now but if you want some more details i will explain you. 希望您现在了解了问题,但是如果您需要更多详细信息,我会向您解释。

The snmpwalk command consists of snmpgetnext commands repeated as long as there is something to be returned in a subtree. snmpwalk命令由重复的snmpgetnext命令组成,只要子树中有要返回的内容即可。 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. 我假设在这种情况下,在单个snmpwalk调用之后发送了两个getnext请求,以确定没有更多数据可检索。 To be sure, please sniffer the traffic using tcpdump or some wireshark solution. 可以肯定的是,请使用tcpdump或一些wireshark解决方案嗅探流量。 Btw. 顺便说一句。 are you sure that -t10 is a right timeout? 您确定-t10是正确的超时时间吗? I would set explicit repetition option to 0 to avoid retransmissions (-r0 option). 我将显式重复选项设置为0以避免重传(-r0选项)。

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. 您要尝试执行的操作是在上述OID上执行snmp get / getnext请求,以执行脚本并将其输出作为SNMP响应返回。 I think that 1 KB problem is caused by something else - it does not seem to be SNMP agent problem in building big responses. 我认为1 KB问题是由其他原因引起的-在构建大响应时,这似乎不是SNMP代理问题。 Please try following SNMPv1 command (if you have SNMPv3 access as well, please let me know): 请尝试执行以下SNMPv1命令(如果您也具有SNMPv3访问权限,请告诉我):

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. 请注意OID末尾的1005个八位位组,用于snmpgetnext请求。 Such OID may not exist, getnext shall access 1006 correctly as it is first, existing OID after 1005. 这样的OID可能不存在,getnext将首先正确访问1006,在1005之后将现有OID访问。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM