Re: scripting help

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Friday, Sep 29th 2006 at 19:56 +0100, quoth Tom Brown:

=>
=>> You set the variable EXITCODE to the standard output of the SNMPWALK
=>> command. I have no idea what you want to do with the output but to check the
=>> exit status you want something like this:
=>> 
=>> $SNMPWALK -v 1 -c $COMMUNITY $HOST $STATUS
=>> EXITCODE=$?
=>> 
=>> Also, do not use backquotes when you can use $( cmd ) instead.
=>> 
=>> output=$($SNMPWALK -v 1 -c $COMMUNITY $HOST $STATUS)
=>
=>i am trying to get a plugin to work that uses snmp to execute checks on remote
=>hosts over snmp and return that value to nagios. I was using this as an
=>assistance
=>
=>http://www.kilala.nl/Sysadmin/retrieve_custom_snmp.php
=>
=>i am no developer thats for sure but i will try to muddle through.
=>
=>any more help appreciated
=>
=>thanks

This might help. Any program that you run can produce output. Any program 
that cleanly exits will produce an exit code. You can save the output of a 
program through tricks like this

prog > file

The exit code is referenced from shell scripts via the variable $?. It 
always contains the value of the exit code of the last command. So if you 
need to examine the exit status of something from a few commands ago, 
then you need to save it in a variable.

prog
EXITCODE=$?
blah
blah
if (( EXITCODE != 0 ))
then 
	# Now we're in trouble...

The use of backquotes causes a command to return the output of the 
program. 

foo=`prog` 

will be equal to the text of whatever was writen during the run of prog.

Make sense?

-- 
Time flies like the wind. Fruit flies like a banana. Stranger things have  .0.
happened but none stranger than this. Does your driver's license say Organ ..0
Donor?Black holes are where God divided by zero. Listen to me! We are all- 000
individuals! What if this weren't a hypothetical question?
steveo at syslang.net


[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux