先安装2个rpm包
#由于两个rpm互相依赖,所以第一个安装的时候需要加上–nodeps参数
rpm -i –nodeps net-snmp-5.4.2.1-8.2.1.x86_64.rpm
rpm -i perl-SNMP-5.4.2.1-8.2.1.x86_64.rpm
#!/bin/sh
groupname=”xxxx”
ipaddress=”192.168.0.xx”
snmpwalk=”/usr/bin/snmpwalk”
export PATH=$PATH:/usr/bin:/bin
#first get all interface
#cmd=”${snmpwalk} -v 2c -c ${groupname} ${ipaddress} ifDescr |egrep \”GigabitEthernet|Copper\” | awk -F’.’ ‘{print $2}’|sed ‘s/STRING: [a-zA-Z0-9]\+\///g’|awk -F ‘=’ ‘{print $2\” \”$1}’|sort -n|awk ‘{print $2}'”
#echo $cmd
interface_list=`${snmpwalk} -v 2c -c ${groupname} ${ipaddress} ifDescr |egrep “GigabitEthernet|Copper” | awk -F’.’ ‘{print $2}’|sed ‘s/STRING: [a-zA-Z0-9]\+\///g’|awk -F ‘=’ ‘{print $2″ “$1}’|sort -n|awk ‘{print $2}’`
#all all interf ‘s status
for inf in $interface_list
do
data=(`/usr/bin/snmpget -v 2c -c ${groupname} ${ipaddress} ifOperStatus.${inf} ifInOctets.${inf} ifInDiscards.${inf} ifInErrors.${inf} ifInUcastPkts.${inf} ifInNUcastPkts.${inf} ifOutOctets.${inf} ifOutDiscards.${inf} ifOutErrors.${inf} ifOutUcastPkts.${inf} ifOutNUcastPkts.${inf}| awk ‘{print $4}’`)
#echo “size:” ${#data[@]}
size=${#data[@]}
if [ $size -ne 11 ];then
continue
fi
open=${data[0]}
inoctets=${data[1]}
echo “open:” $open
echo “inbyte:” $inoctets
done