newbie syntax question

selena selena at
Tue Apr 10 12:31:44 CDT 2001


Roth, Gabrielle writes:
 > I'm maintaining a script written by my predecessor.
 >  Here's the relevant snippet with line numbers:
 >     21 if (open (HINFO, "$snmpget '$router' '$community' '$oid'
 >     2>/dev/null
 > |")) {


 > 1 - (probably more of a unix question) the redirection to
 > /dev/null: I know this isn't the output of the command, because
 > that's available via <INFO> for the parsing loop.  So what is this
 > for?  Is it dumping the exit status?  Is it necessary?  It works
 > without it, but I'm wondering if it's some error handling thing
 > that I can't test and won't know if it's broken until it breaks. :)

the '2>' redirects STDERR to /dev/null.  (in that same context,
'1>/dev/null' would direct STDOUT to /dev/null) depending on what the
fun parsing stuff is, you may/may not want to do something like '2>&1'
to get the STDERR thrown in with the STDOUT and then have some checks
for that...

 > 2 - what is the pipe for at the end of the command?  I've tried it
 > without this and I get this error: failed to run /usr/bin/snmpget
 > at ./mrtg-cpustate line 35.

the pipe at the end of the snmpget command opens a read-only
filehandle that the command writes to. (the perlopentut manpage has
examples of how to use the various redirection operators with open)
you need that pipe so that you'll be able to access the output.

also.. i don't know what other people think of this module, but I use
Net::SNMP instead of calling the snmp* binaries these days.  your
script is pretty straightforward, but if you were to do something more
complicated, you might have a look at it.

i (heart) OOP.


-- you can't breathe life back into a lie.  -- sleater-kinney, leave
you behind

More information about the Pdx-pm-list mailing list