#!/bin/sh

# ./mrtg_eth eth0

PATH=/bin:/usr/bin:/sbin:/usr/sbin

#ip -s link show $1 | head -n 4 | tail -n 1 | (read A B; echo "$A")
#ip -s link show $1 | tail -n 1 | (read A B; echo "$A")
grep "$1:" /proc/net/dev | tr ":" " " | (
  read name \
    rx_bytes rx_packets rx_errs rx_drop \
      rx_fifo rx_frame rx_compressed rx_multicast \
    tx_bytes tx_packets tx_errs tx_drop \
      tx_fifo tx_colls tx_carrier tx_compressed
  if [ "$2" = "packets" ]; then
    echo $rx_packets
    echo $tx_packets
  else
    echo $rx_bytes
    echo $tx_bytes
  fi
)
if uptime | grep -q day
then
  uptime | sed 's/.* up \([^,]*,[^,]*\),.*/\1/'
else
  uptime | sed 's/.* up \([^,]*\),.*/\1/'
fi
hostname
