国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 開發(fā) > Linux Shell > 正文

Shell腳本實(shí)現(xiàn)的單機(jī)流量統(tǒng)計(jì)功能

2020-07-27 19:12:11
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

在網(wǎng)上看到這個(gè)單機(jī)流量的腳本,挺不錯(cuò)的。

復(fù)制代碼 代碼如下:

#!/bin/sh
usage(){
echo “Usage: $0 [-i INTERFACE] [-s INTERVAL] [-c COUNT]”
echo
echo “-i INTERFACE”
echo “    The interface to monitor, default is eth0.”
echo “-s INTERVAL”
echo “    The time to wait in seconds between measurements, default is 3 seconds.”
echo “-c COUNT”
echo “    The number of times to measure, default is 10 times.”
exit 3
}
readargs(){
while [ "$#" -gt 0 ] ; do
  case “$1″ in
   -i)
    if [ "$2" ] ; then
     interface=”$2″
     shift ; shift
    else
     echo “Missing a value for $1.”
     echo
     shift
     usage
    fi
   ;;
   -s)
    if [ "$2" ] ; then
     sleep=”$2″
     shift ; shift
    else
     echo “Missing a value for $1.”
     echo
     shift
     usage
    fi
   ;;
   -c)
    if [ "$2" ] ; then
     counter=”$2″
     shift ; shift
    else
     echo “Missing a value for $1.”
     echo
     shift
     usage
    fi
   ;;
   *)
    echo “Unknown option $1.”
    echo
    shift
    usage
   ;;
  esac
done
}
checkargs(){
if [ ! "$interface" ] ; then
  interface=”eth0″
fi
if [ ! "$sleep" ] ; then
  sleep=”3″
fi
if [ ! "$counter" ] ; then
  counter=”10″
fi
}
printrxbytes(){
/sbin/ifconfig “$interface” | grep “RX bytes” | cut -d: -f2 | awk ‘{ print $1 }'
}
printtxbytes(){
/sbin/ifconfig “$interface” | grep “TX bytes” | cut -d: -f3 | awk ‘{ print $1 }'
}
bytestohumanreadable(){
multiplier=”0″
number=”$1″
while [ "$number" -ge 1024 ] ; do
  multiplier=$(($multiplier+1))
  number=$(($number/1024))
done
case “$multiplier” in
  1)
   echo “$number Kb”
  ;;
  2)
   echo “$number Mb”
  ;;
  3)
   echo “$number Gb”
  ;;
  4)
   echo “$number Tb”
  ;;
  *)
   echo “$1 b”
  ;;
esac
}
 
printresults(){
while [ "$counter" -ge 0 ] ; do
  counter=$(($counter 主站蜘蛛池模板: 黔西县| 黑水县| 石泉县| 康马县| 博罗县| 图木舒克市| 虎林市| 蒙城县| 岳阳县| 万盛区| 辽阳县| 读书| 百色市| 阳高县| 遵义市| 于田县| 巴林右旗| 永新县| 山东省| 阿克陶县| 元氏县| 贵定县| 汤阴县| 曲周县| 青冈县| 卢龙县| 肥乡县| 元江| 南皮县| 长沙县| 长寿区| 新田县| 侯马市| 胶州市| 包头市| 浠水县| 玛多县| 辽阳县| 宜丰县| 高陵县| 虎林市|