LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-24-2009, 01:35 PM   #1
seefor
Member
 
Registered: Mar 2006
Posts: 34

Rep: Reputation: 15
Question Bash and snmpget


Thanks for even looking at this

I have a SNMP script that pull 3 OIDs from a device:
Code:
snmpget -v 1 -Ovq -r 0 -c public 10.75.131.181 .1.3.6.1.4.1.11268.2.1.1.2.29.1.1.4.3.1 .1.3.6.1.4.1.11268.2.1.1.2.29.1.1.4.8.1 .1.3.6.1.4.1.11268.2.1.1.2.29.1.1.4.11.1 |  sed -n '1h;2,$H;${g;s/\n/,/g;p}' >> test
When I run the script I get the following:
Quote:
Error in packet
Reason: (noSuchName) There is no such variable name in this MIB.
Failed object: SNMPv2-SMI::enterprises.11268.2.1.1.2.29.1.1.4.11.1
Code:
# cat test 
15657,2466
How can I set it to output the error to the file?

Example :

Code:
# cat test 
15657,2466,NA
Thanks in advance for you help or suggestion.
SeeFor
 
Old 04-01-2009, 01:00 PM   #2
PTrenholme
Senior Member
 
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,187

Rep: Reputation: 354Reputation: 354Reputation: 354Reputation: 354
I suspect that the error message is being written to /dev/stderr, and all you'd need to do is capture the message to a file (e.g., 2>/tmp/errors or the like), and then parse the error(s).

Note: Just guessing because nobody more knowledgeable than I has yet replied to your inquiry.
 
Old 04-01-2009, 01:16 PM   #3
dwhitney67
Senior Member
 
Registered: Jun 2006
Location: Maryland
Distribution: Kubuntu, Fedora, RHEL
Posts: 1,541

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
Maybe after running the snmpget, the shell's status is set to a non-zero value to indicate an error; thus perhaps $? can be used. I'm not sure though if the sed will affect this value or not.

Code:
sed_res=`snmpget -v 1 -Ovq -r 0 -c public 10.75.131.181 .1.3.6.1.4.1.11268.2.1.1.2.29.1.1.4.3.1 .1.3.6.1.4.1.11268.2.1.1.2.29.1.1.4.8.1 .1.3.6.1.4.1.11268.2.1.1.2.29.1.1.4.11.1 | sed -n '1h;2,$H;${g;s/\n/,/g;p}'`

if [ $? -eq 0 ]
then
        echo "$sed_res" >> test
else
        echo "$sed_res,NA" >> test
fi
 
  


Reply

Tags
bash



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
snmpget error immortaltechnique Linux - Software 2 09-26-2012 10:56 AM
snmpget form c cools Programming 1 07-01-2007 06:31 PM
SNMPGET and SNMPBULKWALK error elnunez Linux - Networking 0 06-27-2006 05:11 AM
help with snmpget alaios Linux - Networking 4 08-25-2005 06:43 AM
snmpget ARP table of router parker Programming 0 08-14-2003 01:42 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:08 AM.

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