The easy way around multiple calls to write is to remove the redirection
from within the script itself and the just redirect at the command line to
pass the output into the RESULT.CVS file.

MY_SNMP_SCRIPT > RESULTS.cvs

#!/bin/sh -x
LOG=RESULT.csv
public="public"
snmp="/usr/bin/snmpwalk -Ov -v1 -c $public"
oid=`cat OID_LIST`
RTR=`cat RTR_LIST`

for i in $RTR
  # send the ip address to the results files without a newline
  do echo -n $i
for n in $oid
  # send the snmp result to the resutls file without a newline
  do  echo -n ","`$snmp $i $n|cut -f2 -d:`
  done
  # send a newline to the results files to start the overall loop on a
newline in the results file
  echo -e \n
  done
###END

Thank you
Russell


On Thu, Feb 4, 2016 at 11:28 AM, Glenn Stone <technosha...@liawol.org>
wrote:

> On Thu, Feb 04, 2016 at 10:28:08AM -0500, Russell Evans wrote:
> >Since you are just using echo to populate the RESULT.csv, you can use the
> >-n option in it to create a single line entry of the snmp returnsand then
> >use the -e option to send a newline at the end of the snmp loop to close
> >the single line input.
>
> This doesn't scale, though; you want to minimize your calls to write()...
> if
> there are just a few hundred, no big, but hitting the disk is the most
> expensive thing you can do... On the gripping hand, if for some strange
> reason you ended up with an entry a couple meg long, that could run into
> the
> environment variable space limit, but for *this* functionality, I think
> it'll be fine. :)
>
> -- Glenn
> Think BIG!
>

Reply via email to