Below is the output information of my wlan0 NIC, you can use Ifconfig or Ifconfig | Sed-n '/wlan0/,10p ' gets the format of the displayed information
wlan0 Link encap:ethernet hwaddr xx:xx:xx:xx:xx:xx
inet addr:172.29.164.251 bcast:172.29.167.255 mask:255.255.248.0
INET6 addr:2001:da8:c803:4a57:e190:606f:3155:9369/64 Scope:global
INET6 addr:fe80::6e71:d9ff:fe0b:27f6/64 scope:link
INET6 addr:2001:da8:c803:4a57:6e71:d9ff:fe0b:27f6/64 Scope:global
Up broadcast RUNNING multicast mtu:1500 metric:1
RX packets:1305 errors:0 dropped:0 overruns:0 frame:0
TX packets:647 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:370741 (362.0 KiB) TX bytes:117872 (115.1 KiB)
The following script obtains the last line of Rx, TX information at two points in time, and then counts the total traffic over time.
The final printout statistics are on the screen.
#!/bin/bash
#network Traffic Statistics
#Write by Ricardo.su 2015-04-30
time_range=10
Time= ' Date +%m '-"%d" "%k": "%m"
rx_point_1= ' Ifconfig wlan0 | grep [[: Space:]]rx.*tx | awk ' {print $} ' | Cut-c7-'
tx_point_1= ' Ifconfig wlan0 | grep [[: Space:]]rx.*tx | awk ' {print $6} ' | Cut-c7-'
Sleep $TIME _range
Rx_point_2= ' Ifconfig wlan0 | grep [[: Space:]]rx.*tx | awk ' {print $} ' | Cut-c7-'
Tx_point_2= ' Ifconfig wlan0 | grep [[: Space:]]rx.*tx | awk ' {print $6} ' | Cut-c7-'
Rx_rs=$ (((rx_point_2-rx_point_1)/1024))
Tx_rs=$ (((tx_point_2-tx_point_1)/1024))
echo "Date $time"
echo "Average Network traffic in $TIME _range s:rx $rx _rs kb TX $tx _rs KB"
Write a shell script to count the local traffic over a period of time