#!/bin/sh ## ## SCRIPT NAME: get_net_stats.sh ## ## PURPOSE: ## Gets 'RX' (received) and 'TX' (transmitted) data from output of ## the 'netstat' command (or some other command supplying the same data). ## ##+############################################ ## Example output from the 'netstat -i' command: ## ## Kernel Interface table ## Iface MTU Met RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg ## eth0 1500 0 23449 0 0 0 19670 0 0 0 BMRU ## lo 16436 0 4 0 0 0 4 0 0 0 LRU ## wlan0 1500 0 0 0 0 0 0 0 0 0 BMU ## wmaster0 0 0 0 0 0 0 0 0 0 0 RU ## ##+######################################################### ## ALTERNATIVELY, we could use 'ifconfig -a -s', which gives: ## ## Iface MTU Met RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg ## eth0 1500 0 23449 0 0 0 19670 0 0 0 BMRU ## lo 16436 0 4 0 0 0 4 0 0 0 LRU ## wlan0 1500 0 0 0 0 0 0 0 0 0 BMU ## wmaster0 0 0 0 0 0 0 0 0 0 0 RU ## ## where '-a' stands for 'all' --- and '-s' stand for 'summary'. ##+######################################################################## ## ## This script gets the data from the 'RX-OK' and 'TX-OK' columns. ## ## INPUT: a single argument supplies an interface ID, such as ## 'eth0' or 'eth1' or 'wlan0'. ## ## CALLED BY: a Tk GUI script that shows 'RX' and 'TX' DIFFERENCE data ## --- i.e. RATE data --- ## as needle readings on a couple of meters (dials) drawn ## on a Tk canvas --- Tk script name: ## meters_net_stats.tk ## ## MAINTENANCE HISTORY: ## Updated by: Blaise Montandon 2013sep05 Started this script on Linux, ## using Ubuntu 9.10 (2009 October, ## 'Karmic Koala'). ## Updated by: Blaise Montandon 20....... ##+######################################################################## ## FOR TESTING: # set -x if test "$1" = "" then echo "ERROR: Missing argument. Need a network interface ID." exit fi ## ALTERNATIVE: # ifconfig -a -s | grep "^$1" | awk '{print $4 " " $8}' netstat -i | grep "^$1" | awk '{print $4 " " $8}'