#!/usr/bin/perl
# by c. ellwood
use strict;

my $interface = 'eth0';
my $statfile = '/proc/net/dev';
my $uptimefile = '/proc/uptime';     # Set to program to give system uptime
my $hostname = 'x.mikeynet.com';

# Clear path and get uptime
delete $ENV{PATH};
delete $ENV{BASH_ENV};
my ($in, $out, $uptime);

open(UPTIME, $uptimefile) || die "Cannot open $uptimefile: $!\n";
$uptime = <UPTIME>;
($uptime,my $trash) = split(' ', $uptime);
close(UPTIME);

open(STATS, $statfile) || die "Cannot open $statfile: $!\n";
while (<STATS>) {
        my $line = $_;
        chomp($line);
        if ($line =~ /^\s+$interface:\s*(\d+)\s+\d+\s+\d+\s+\d+\s+\d+\s+\d+\s+\d+\s+\d+\s+(\d+)\s+\d+\s+\d+\s+\d+\s+\d+\s+\d+\s+\d+\s+\d+$/) {
              $in = $1;
              $out = $2;
              last;
        }
}
close(STATS);

print "$in\n$out\n$uptime\n$hostname: Interface: $interface\n";
