Skip to content

Instantly share code, notes, and snippets.

@jyotty
Last active September 11, 2019 14:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jyotty/5052108 to your computer and use it in GitHub Desktop.
Save jyotty/5052108 to your computer and use it in GitHub Desktop.
Parsing /proc/net/dev with perl for @ChrisLundquist
#!/usr/bin/env perl
use strict;
use warnings;
my @lines = `cat /proc/net/dev`;
my @rx_fields = qw(bytes packets errs drop fifo frame compressed multicast);
my @tx_fields = qw(bytes packets errs drop fifo frame compressed);
for my $line (@lines) {
next if $line !~ /:/;
$line =~ s/^\s+|\s+$//g;
my ($iface, %rx, %tx);
($iface, @rx{@rx_fields}, @tx{@tx_fields}) = split /[: ]+/, $line;
print "iface: $iface\n";
print "rx{$_}: $rx{$_}\n" for sort keys %rx;
print "tx{$_}: $tx{$_}\n" for sort keys %tx;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment