#!/bin/sh

# used with analyze_interface_bytes tool
# maybe run via cron every hour

LOGFILE=/home/reed/interface_bytes.log
TIMESTAMP=`date +%s`

# this routine is for Linux or System V that has /proc/net/dev
cat /proc/net/dev | \
 awk -v "timestamp=$TIMESTAMP" '/ eth/ {
       gsub ("/[[:blank:]]\{1,\}", " ");
       gsub ("/^[[:blank:]]/", "");
       gsub ("\:", " ");
       print timestamp"\t"$1"\t"$2"\t"$10;
     }' >> $LOGFILE


# this routine is for BSD netstat
# netstat -ib | \
# awk '/^ne0/ {if ($3 == "<Link>") print systime()"\tne0\t"$5"\t"$6;}' \
# >> $LOGFILE

# notes below:

#(date +%s ; grep "eth"  /proc/net/dev ) >> $LOGFILE

# awk:       "date +%s" | getline date;

# this routine below can convert old proc format to new format
#cat ../interface_bytes.log | sed -e 's/[[:blank:]]\{1,\}/ /g' | sed -e 's/\:/ /' | while read timestamp ; do read a b c d e f g h i j k ; echo $timestamp      eth0    $b      $j; read a b c d e f g h i j k l; shift ; echo $timestamp       eth1    $b      $j; done > ../interface_bytes.log.converted

