Hunter的大杂烩

May 11, 2012

suse下通过snmp获取交换机信息脚本

Filed under: 技术话题 — hunter @ 6:19 pm

先安装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

No Comments

No comments yet.

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.

Powered by WordPress