Linux to monitor network traffic script _linux Shell

Source: Internet
Author: User
I looked at the/proc/net/dev under Linux to record the number of packets and bytes sent and received by each network card. So initiation thought, wrote one. Operation Effect:

Copy Code code as follows:

[root@74-82-173-217 ~]#./net.sh
Current Ip:inet addr:74.82.173.217 bcast:74.82.173.223 mask:255.255.255.224
Summry info:rx bytes:203692709 (194.2 MiB) TX bytes:93525930 (89.1 MiB)
Eth0 Receive bytes:573 Packets:3
Eth0 Send bytes:3086 Packets:3
Eth0 Receive bytes:378 packets:7
Eth0 Send bytes:11236 packets:7
Eth0 Receive bytes:324 Packets:6
Eth0 Send bytes:444 Packets:2
Eth0 Receive bytes:54 packets:1
Eth0 Send bytes:0 packets:0


The content of the specific script is as follows, almost no need to modify, you can get any machine to use.
Copy Code code as follows:

[root@74-82-173-217 ~]# Cat net.sh
#! /bin/bash
#Author: Vogts Wangtao 2008-12-18
#Get Summry Info
echo "Current Ip:" '/sbin/ifconfig eth0 | grep inet '
echo "Summry info:" '/sbin/ifconfig eth0 | grep bytes '
#sleep 1 second, monitor eth0
While True
Todo
receive1= ' Cat/proc/net/dev|grep eth0 | awk ' {print$1} ' |sed-s ' s/eth0://g '
receive_pack1= ' Cat/proc/net/dev|grep eth0 | awk ' {print$2} '
send1= ' Cat/proc/net/dev|grep eth0 | awk ' {print$9} '
send_pack1= ' Cat/proc/net/dev|grep eth0 | awk ' {print$10} '
Sleep 1
Receive2= ' Cat/proc/net/dev|grep eth0 | awk ' {print$1} ' |sed-s ' s/eth0://g '
Receive_pack2= ' Cat/proc/net/dev|grep eth0 | awk ' {print$2} '
receive_cnt= ' Expr $receive 2-$receive 1 '
receive_pack_cnt= ' expr $receive _pack2-$receive _pack1 '
Send2= ' Cat/proc/net/dev|grep eth0 | awk ' {print$9} '
Send_pack2= ' Cat/proc/net/dev|grep eth0 | awk ' {print$10} '
send_cnt= ' Expr $send 2-$send 1 '
send_pack_cnt= ' expr $send _pack2-$send _pack1 '
Echo ' eth0 Receive Bytes: ' $receive _cnt ' Packets: ' $receive _pack_cnt
Echo ' eth0 Send Bytes: ' $send _cnt ' Packets: ' $send _pack_cnt
Done
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.