3

I want to shell execute a script through SNMP command.So for that script i have configured OID in snmpd.conf under /etc/snmp folder.

My script looks like working is just to redirect "text" to output.txt file and then print script executed on console.

#!/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"

Output

if i am using snmpwalkcommand from node ...1

snmpwalk command the output is

a

and the updated output.txt file is 1 2

snmpwalk command the output is

c

and the updated output.txt file is 1 2 3 4

snmpwalk command the output is

c

and the updated output.txt file is 1 2 3 4 5

Which means i am getting a,c,e ... but i need a,b,c,d,e

This type of processing i am doing because data is more that 1 kb in output.txt and i am not able to fetch more than 1 kb record in snmpget command, that's why i am doing this process to get whole data.

1 Answer 1

0

a) try to include a "shebang" line (#!/bin/sh) as very first line of your script

b) try to set full path to your file, like echo "text" > /tmp/output.txt

c) be sure that path you write to is writable by UID of snmpd (/tmp/ usually is)

Sign up to request clarification or add additional context in comments.

1 Comment

I think the issue here is related to buffed operation. Just my guess. Because looks like echo/sed etc commands do buffered read/write which is causing the problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.