bash: adding various names to associated interface names in a list

61 Views Asked by At

I'm maintaining a network monitoring tool, and am trying to set up custom polling for trunk interfaces. The tool has its own proprietary scripts that do a variety of things.

So far, I have a script that I feed a file full of node names, and it echos the names along with the output from a script that performs an SNMP walk against the trunk OID: 1.3.6.1.4.1.9.9.46.1.6.1.14 -- the output gives me a node name, and then no lines if no interfaces trunk, or a node name followed by lines of interface numbers on the devices:

#!/bin/bash
for nodename in $(cat listofnodes.txt);
   do
        echo $nodename >> nodewithtrunkinterfaces.txt
        snmpwalkscript.pl @nodename .1.3.6.1.4.1.9.9.46.1.6.1.1.14 | grep 'trunking: yes' >> nodewithtrunkinterfaces.txt

done

The next step will be to take the relevant resultant information and run another proprietary script to set a custom attribute, and set up a polling policy in the tool interface.

I have tested using sed to remove the extra text, leaving me with a node name, and a list of interface numbers - problem is I need the correct node name next to each interface number to be correctly processed by the next .pl that will add a custom attribute to each trunk interface - is there a simple or simple-ish way to do that?

0

There are 0 best solutions below