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

首頁 > 系統(tǒng) > Linux > 正文

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

2019-10-26 18:43:03
字體:
來源:轉載
供稿:網(wǎng)友

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

代碼如下:
#!/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”

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 冕宁县| 定日县| 东城区| 若尔盖县| 定日县| 广南县| 靖州| 大邑县| 靖安县| 郯城县| 福海县| 河北省| 明光市| 博爱县| 田阳县| 黄龙县| 台东市| 台中县| 阿尔山市| 驻马店市| 桑植县| 新干县| 河北省| 肥城市| 新巴尔虎左旗| 青海省| 郸城县| 浙江省| 钟山县| 九龙坡区| 隆尧县| 遵化市| 西宁市| 县级市| 阿鲁科尔沁旗| 全椒县| 南宁市| 哈尔滨市| 花莲市| 崇文区| 苗栗市|