[Original] getting Linux network traffic script

Source: Internet
Author: User
Get Linux network traffic script

Syntax: [-- 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 "

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.