首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用SNMP协议通过SNMP命令运行脚本会提供不同的输出,作为脚本执行独立

使用SNMP协议通过SNMP命令运行脚本会提供不同的输出,作为脚本执行独立
EN

Stack Overflow用户
提问于 2012-12-12 04:59:16
回答 1查看 3.1K关注 0票数 3

我想通过SNMP command.So执行一个脚本,这个脚本是我在snmpd.conf中在/etc/snmp文件夹下配置的。

我的脚本看起来只是将"text"重定向到output.txt文件,然后打印在控制台上执行的脚本。

代码语言:javascript
复制
#!/usr/bin/ksh 

Input_path="$HOME/input.txt"     
Out_Path="$HOME/output.txt"     

#I have to take the line_num from output.txt which is actually number of line present in output.txt 
line_num=`wc -l <$out` 

#after that i need to take that line from INPUT file
line=`head -$a $Input_path | tail -1 ` 

#i need to uppend data to 1 kb for that i am using typset command
typeset -L1024 line 

#I am increasing value of a
a=`expr $a + 1` 

#same i am echo in file so at this point number of line in file will increase by 1
echo $a >> $Out_Path

#this is the final output which i want .
echo -e "$line\n"

输出

如果我使用的是节点...1中的snmpwalkcommand命令

snmpwalk命令的输出是

一个

更新后的output.txt文件为12。

snmpwalk命令的输出是

C

更新后的output.txt文件为1 2 3 4

snmpwalk命令的输出是

C

更新后的output.txt文件为1 2 3 4 5

也就是说我得到了一个,c,e.但我需要a,b,c,d,e

这种类型的处理是因为output.txt中的数据大于1kb,而且我不能在snmpget命令中获取超过1kb的记录,这就是为什么我要做这个过程来获取整个数据。

EN

回答 1

Stack Overflow用户

发布于 2012-12-12 05:30:39

( a)尝试将"shebang“行(#!/bin/sh)作为脚本的第一行

( b)尝试设置文件的完整路径,如echo "text" > /tmp/output.txt

c)确保写入的路径由snmpd的UID可写(/tmp/通常是)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13833078

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档