shell脚本网络流量实时查看
Linux网络流量实时查看脚本,Centos默认没有自带流量查看工具,通过网上的资料做了一些修改
#!/bin/bash # Author: Ca0gu0 # Script Name: idev.sh # Date:2014-06-03 while [ True ];do i=0 for eth in $(cat /proc/net/dev | sed -e '1,2d'|cut -d: -f1);do RX[$i]=$(cat /proc/net/dev | grep $eth | tr : " " | awk '{print $2}') TX[$i]=$(cat /proc/net/dev | grep $eth | tr : " " | awk '{print $10}') let i=$i+1 done sleep 1 clear i=0 for eth in $(cat /proc/net/dev | sed -e '1,2d'|cut -d: -f1);do RXnext[$i]=$(cat /proc/net/dev | grep $eth | tr : " " | awk '{print $2}') TXnext[$i]=$(cat /proc/net/dev | grep $eth | tr : " " | awk '{print $10}') let i=$i+1 done i=0 echo -e "\t RX `date +%k:%M:%S` TX" for eth in $(cat /proc/net/dev | sed -e '1,2d'|cut -d: -f1);do RX=$((${RXnext[$i]}-${RX[$i]})) TX=$((${TXnext[$i]}-${TX[$i]})) if [[ $RX -lt 1024 ]];then RX="${RX}B/s" elif [[ $RX -gt 1048576 ]];then RX=$(echo $RX | awk '{print $1/1048576 "MB/s"}') else RX=$(echo $RX | awk '{print $1/1024 "KB/s"}') fi if [[ $TX -lt 1024 ]];then TX="${TX}B/s" elif [[ $TX -gt 1048576 ]];then TX=$(echo $TX | awk '{print $1/1048576 "MB/s"}') else TX=$(echo $TX | awk '{print $1/1024 "KB/s"}') fi echo -e "$eth \t $RX $TX " let i=$i+1 done done
每秒钟刷新一次