获取Linux网络流量脚本

语法:[--help] [-i] [-d]

#!/bin/bash

VERSION="1.0.0.1"
eth=""
sec=0

help()
{
  printf "Version: $VERSION \n\
  Usage: $0 [-i interface] [-d time]\n\
  \t-i|--interface     : The needs of the inquiries Interface Network Card (such as eth0, eth1...)\n\
  \t-d|--time          : Delay time(seconds)\n";
}


echo "$*"
for dummy
do
 case $1 in
  --help) help; exit 1;;
  -i|--interface) shift; eth=$1;;
  -d|--time) shift; sec=$1;;  
 esac
 shift
done


#echo -n "Please enter the needs of the inquiries Interface Network Card (such as eth0, eth1...): "
#read eth
echo "Your input data is:"$eth
#echo -n "Input delay time(seconds):"
#read sec
echo "You are calculated within "$sec" seconds of the average flow, Please wait... "
infirst=$(awk '/'$eth'/{print $1 }' /proc/net/dev |sed 's/'$eth'://')
outfirst=$(awk '/'$eth'/{print $10 }' /proc/net/dev)
sumfirst=$(($infirst+$outfirst))
sleep $sec"s"
inend=$(awk '/'$eth'/{print $1 }' /proc/net/dev |sed 's/'$eth'://')
outend=$(awk '/'$eth'/{print $10 }' /proc/net/dev)
sumend=$(($inend+$outend))
sum=$(($sumend-$sumfirst))
echo $sec"(s) total flow is: "$sum" bytes"
aver=$(($sum/$sec))
echo "The average flow is: "$aver" bytes/sec"

相关文章:

  • 2022-12-23
  • 2022-01-14
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-04-11
  • 2021-06-30
  • 2021-11-15
猜你喜欢
  • 2021-03-30
  • 2022-01-17
  • 2022-12-23
  • 2022-02-10
  • 2021-07-10
  • 2021-12-27
相关资源
相似解决方案