0

I am working on a script to filter community entries from snmpd.conf Script is:

SERVER=$(hostname)
touch /tmp/snmp_audit_$SERVER
echo $SERVER >> /tmp/snmp_audit_$SERVER
SNMP=$(cat /etc/snmp/snmpd.conf |grep -i rocommunity | awk '{print $1,$2,$3}'
echo $SNMP >> /tmp/snmp_audit_$SERVER

Which gives me output in below format:

rocommunity XXXX 1nn.nn.nnn.40
rocommunity XXXX 1nn.nn.nnn.0/24
rocommunity XXXX 1nn.nn.nnn.30

However, I want to filter those servers only, which doesn't have any of the below entries in snmpd.conf:

rocommunity XXXX 127.10.30.40
rocommunity XXXX 192.10.30.0/24
rocommunity XXXX 192.20.100.30

And for all those which doesn't have these entries, later I would need to add these ranges. Also, I need to run it on multiple server over ssh, from a jump server where I have list of server names in a file. Please advice.

1 Answer 1

1

You can do this with grep:

grep -vxFf exclude.txt /etc/snmp/snmpd.conf 

Put the below entries in exclude.txt, basically it is your exclusion list:

rocommunity XXXX 127.10.30.40
rocommunity XXXX 192.10.30.0/24
rocommunity XXXX 192.20.100.30
  • -f exclude.txt reads the pattern to match from file exclude.txt

  • -F does fixed string matching instead of Regex pattern matching

  • -x matches whole lines

  • -v inverses the operation i.e. only non-matching lines will be shown

1
  • This will give me entries except the: "rocommunity XXXX 127.10.30.40 rocommunity XXXX 192.10.30.0/24 rocommunity XXXX 192.20.100.30" However, I am looking for a way to search servers which doesn't have these entries updated in /etc/snmp/snmpd.conf file. I didn't mean to get the entries excluding few specific. I mean to get the servers name which doesn't have any of these entries mentioned in /etc/snmp/snmpd.conf file.
    – Bela
    Commented Aug 28, 2016 at 5:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .