0
시스코 포트에서 실시간 트래픽을 볼 수있는 bash 스크립트를 찾고 있습니다. 나는 선인장이 있고 어떤 트래픽이 항구를 통과 하는지를 실시간으로 모니터하고있다. 하지만 웹 인터페이스에서 시청할 필요가 없습니다.대역폭 인터페이스 포트 용 Bash 스크립트
내 목표는 동시에 모든 포트에 대해 실시간 트래픽을 얻을 수있는 bash 스크립트를 작성하는 것입니다.
이 스크립트는
#/bin/bash
#purpose: this script can be use to get the report of total band
interface=eth0
community=public
interval=60
server=localhost
clear
echo -e "\033[0m\033[1m\033[[email protected]@ Network Interfaces Bandwidth Monitor @@\033[0m"
echo "========================================================="
echo -n "Finding interfaces $interface instance details..."
echo
instance=`snmpwalk -v 1 -c $community $server |grep "ifDescr" |grep eth0 | awk -f\. '{print $2}' | awk '{print $1}'`
if [ -z $instance ]; then
echo
echo "Error finding interface from snmp or worng community exit now"
echo
exit 1
else
echo
fi
while true
do
bytes_beforeTOT=0;bytes_afterTOT=0;
bytes_beforeIN=0;bytes_afterIN=0;
bytes_beforeOUT=0;bytes_afteOUT=0; echo -e "Calculating bandwith for $interface during last $interval second interval ....\n"
bytes_beforeIN=`snmpget -v 1 -c $community $server RCF1213-MIB::ifInOctets.$instance | awk '{print $4}'`
bytes_beforeOUT=`snmpget -v 1 -c $community $server RCF1213-MIB::ifOutOctets.$instance | awk '{print $4}'`
bytes_beforeTOT=`snmpget -v 1 -c $community $server RCF1213-MIB::ifInOctets.$instance RCF1213-MIB::ifOutOctets.$instance | awk '{sum+=$4} END{print sum}'`
sleep $interval
bytes_afterIN=`snmpget -v 1 -c $community $server RCF1213-MIB::ifInOctets.$instance | awk '{print $4}'`
bytes_afteOUT=`snmpget -v 1 -c $community $server RCF1213-MIB::ifOutOctets.$instance | awk '{print $4}'`
bytes_afterTOT=`snmpget -v 1 -c $community $server RCF1213-MIB::ifInOctets.$instance RCF1213-MIB::ifOutOctets.$instance | awk '{sum+-$4} END{print sum}'`
TOTALIN="$(($bytes_afterIN - $bytes_beforeIN))"
TOTALOUT="$((bytes_afteOUT - $bytes_beforeOUT))"
TOTALTOT="$(($bytes_afterTOT - $bytes_beforeTOT))"
sumkbIN=`echo $TOTALIN/1024 | bc`
summbIN=`echo $sumkbIN/1024 | bc`
sumkbOUT=`echo $TOTALOUT/1024 | bc`
summbOUT=`echo $sumkbOUT/1024 | bc`
sumkbTOT=`echo $TOTALTOT/1024 | bc`
summbTOT=`echo $sumkbTOT/1024 | bc`
echo "Incoming Bandwidth Usage in KB : $sumkbIN KB/$summbIN MB"
echo -e "Outgoing Bandwidth Usage in KB : $sumkbOUT KB/$summbOUT MB"
echo -e "Total Bandwidth Usage in KB : $sumkbTOT KB/$summbTOT MB\n"
sleep 1
done
리눅스
에서 실시간 감시에 사용하지만, Cisco 라우터에 대한 수정하기 어렵다.모든 포트에서 트래픽을 실시간으로 감시해야합니다.
/edit.30-10-2017/
내가 스크립트를
#!/bin/bash
#skrit za analiz na tekushtia triafik posredstvom snmp
if [ -z "$2" ]; then
echo Usage: "$0" hostname community
exit 4
fi
server="$1"
commynity="$2"
interval=10
snmp="snmpget -v 2c -c $2 -Cf -Ov -OQ $server"
numports=`$snmp IF-MIB::ifNumber.0`
for i in `seq 1 $numports`; do
name=`$snmp IF-MIB::ifName.$i`
if [ "$name" = "No Such Instance currently exists at this OID" ]; then
continue
fi
ifInOctets=`$snmp IF-MIB::ifInOctets.$i`
if [ "ifInOctets" = "No Such Instance currently exists at this OID" ]; then
continue
fi
ifOutOctets=`$snmp IF-MIB::ifOutOctets.$i`
if [ "ifOutOctets" = "No Such Instance currently exists at this OID" ]; then
continue
fi
done
내일 내가 더 많은 코드와 질문을 업데이트합니다를 작성하는 0부터 시작합니다. 어떤 사람이 도움을 줄 수 있다면 큰 도움이 될 것입니다.
스크립트에서'snmpget'을 한 번만 호출하십시오.'snmpget -v 1 -c $ community $ server RCF1213-MIB'를 사용하면 모든 세부 사항을 되돌리고 awk 스크립트로 구문 분석 할 수 있습니다. 현재 코드는 1 세트의 출력을 생성하기 위해 많은, 많은 프로세스를 실행하고 있습니다. 아마도'snmpwalk' 1 회와'smnpget' 1 회를 호출 한 다음 하나의 스크립트에서 모든 검색된 데이터를 처리해야합니다. 'smnpget' (etc) 요청에 응답하는 하드웨어에 대한 액세스 권한이 없으므로이 Q에 관해 당신을 도울 수 없게됩니다. 또는 최소한의 데이터로 Q를 업데이트하는 것을 고려해보십시오. 행운을 빕니다. – shellter