#!/bin/bash # Traffic Monitor # author: Xiao Guaishou get_traffic_info(){ recv=`cat /proc/net/dev | awk -F '[: ]+' '/'"$dev"'/{print $3}'` sent=`cat /proc/net/dev | awk -F '[: ]+' '/'"$dev"'/{print $11}'` } get_traffic_rate(){ In=`echo $[($recv - $old_recv) / 1024]` Out=`echo $[($sent - $old_sent) / 1024]` } read -p '请输入你要监控的网卡设备名:' dev if ! grep -qP "$dev:" /proc/net/dev then echo "你输入的设备不存在,或不是合法的网卡设备" exit 1 fi while :; do get_traffic_info old_recv=$recv old_sent=$sent sleep 1 get_traffic_info get_traffic_rate echo -e "$dev Input: $In KB/s Output: $Out KB/s " done # End