#!/usr/local/bin/bash
echo|gawk -v ip="$1" -v q="'" '\
BEGIN \
{ \
l=0;while(("snmpbulkwalk -v2c -c mrtg -Ovq -m " q q " " ip " 1.3.6.1.4.1.171.12.1.2.10.1.1.1")|getline) { \
	l++; \
	ssm[l]=$1; \
	ssk[$1]="EXISTS"; \
	} \
for(i=2;i<=9;i++) { \
	j=0; \
	while(("snmpbulkwalk -v2c -c mrtg -Ovq -m " q q " " ip " .1.3.6.1.4.1.171.12.1.2.10.1.1." i )|getline) { \
		j++; \
		sm[j]=sm[j] " " $1; \
		} \
	} \
split(ip,ipp,".");subnet=ipp[1] "." ipp[2] "." ipp[3] ".0"; \
lm[1]=" 10.0.0.0 1 255.255.255.0 1 1 1 1 1"; \
lm[2]=" 10.112.155.0 1 255.255.255.128 2 1 2 1 2"; \
lm[3]=" " subnet " 1 255.255.255.0 2 1 2 2 2"; \
lm[4]=" 78.40.80.180 1 255.255.255.255 1 1 1 1 1"; \
lm[5]=" 10.160.8.0 1 255.255.255.0 1 1 1 1 1"; \
lm[6]=" 10.160.9.0 1 255.255.255.0 2 1 2 1 2"; \
lm[7]=" 192.168.9.0 1 255.255.255.0 2 1 2 1 2"; \
for(k in sm) { \
	for(m in lm) { \
		if(lm[m]==sm[k]) { \
			delete lm[m];delete sm[k]; \
			} \
		} \
	} \
o=0; \
for(m in lm) { \
	if(lm[m]!="") { \
		do { o++ \
		} while((o in ssk)) \
			ssk[o]="EXISTS";
			print "add    : " o lm[m]; \
			split(lm[m],slm," "); \
			system(("snmpset -v2c -c mrtg -m " q q " " ip \
				" 1.3.6.1.4.1.171.12.1.2.10.1.1.2." o " a " slm[1] \
				" 1.3.6.1.4.1.171.12.1.2.10.1.1.3." o " i " 4 \
				" 1.3.6.1.4.1.171.12.1.2.10.1.1.4." o " a " slm[3] \
				" 1.3.6.1.4.1.171.12.1.2.10.1.1.5." o " i " slm[4] \
				" 1.3.6.1.4.1.171.12.1.2.10.1.1.6." o " i " slm[5] \
				" 1.3.6.1.4.1.171.12.1.2.10.1.1.7." o " i " slm[6] \
				" 1.3.6.1.4.1.171.12.1.2.10.1.1.8." o " i " slm[7] \
				" 1.3.6.1.4.1.171.12.1.2.10.1.1.9." o " i " slm[8] \
				" >/dev/null")); \
			} \
	} \
for(k in sm) { \
        if(sm[k]!="") { \
                print "delete : " ssm[k] sm[k]; \
                delete sm[k]; \
                system(("snmpset -v2c -c mrtg -m " q q " " ip " 1.3.6.1.4.1.171.12.1.2.10.1.1.3." ssm[k] " i 6 >/dev/null")); \
                } \
        } \

} \
'
