diff options
author | Stephen Hemminger <stephen.hemminger@vyatta.com> | 2010-03-12 13:36:23 -0800 |
---|---|---|
committer | Stephen Hemminger <stephen.hemminger@vyatta.com> | 2010-03-12 13:36:23 -0800 |
commit | d193976a132fe96b4f1b3fe19219bb6726d4b668 (patch) | |
tree | 20ca06d74562f5e450ffd57f4acca52f4d4ce7bd | |
parent | fd38676b38a2ae107fe4884717eda7acb56df0a5 (diff) | |
download | vyatta-op-d193976a132fe96b4f1b3fe19219bb6726d4b668.tar.gz vyatta-op-d193976a132fe96b4f1b3fe19219bb6726d4b668.zip |
Don't give error if /var/run/vyatta doesn't exist yet
clear counters might be run when /var/run/vyatta hasn't been
created yet.
Also cleanup some identation and declarations
-rwxr-xr-x | scripts/vyatta-show-interfaces.pl | 44 |
1 files changed, 25 insertions, 19 deletions
diff --git a/scripts/vyatta-show-interfaces.pl b/scripts/vyatta-show-interfaces.pl index 063eb98..1b662c8 100755 --- a/scripts/vyatta-show-interfaces.pl +++ b/scripts/vyatta-show-interfaces.pl @@ -88,26 +88,29 @@ sub get_clear_stats { foreach my $var (@rx_stat_vars, @tx_stat_vars) { $stats{$var} = 0; } - my $FILE; + my $filename = get_intf_statsfile($intf); - if (!open($FILE, '<', $filename)) { - return %stats; - } - my $magic = <$FILE>; chomp $magic; + open (my $f, '<', $filename) + or return %stats; + + my $magic = <$f>; + chomp $magic; if ($magic ne $clear_file_magic) { print "bad magic [$intf]\n"; return %stats; } - my $timestamp = <$FILE>; chomp $timestamp; + + my $timestamp = <$f>; + chomp $timestamp; $stats{'timestamp'} = $timestamp; - my ($var, $val); - while (<$FILE>) { + + while (<$f>) { chop; - ($var, $val) = split(/,/); + my ($var, $val) = split(/,/); $stats{$var} = $val; } - close($FILE); + close($f); return %stats; } @@ -276,18 +279,21 @@ sub run_clear_intf { foreach my $intf (@intfs) { my %stats = get_intf_stats($intf); - my $FILE; my $filename = get_intf_statsfile($intf); - if (!open($FILE, ">", $filename)) { - die "Couldn't open $filename [$!]\n"; - } + + mkdir $clear_stats_dir unless ( -d $clear_stats_dir ); + + open(my $f, '>', $filename) + or die "Couldn't open $filename [$!]\n"; + print "Clearing $intf\n"; - print $FILE $clear_file_magic, "\n", time(), "\n"; - my ($var, $val); - while (($var, $val) = each (%stats)) { - print $FILE $var, ",", $val, "\n"; + print $f $clear_file_magic, "\n", time(), "\n"; + + while (my ($var, $val) = each (%stats)) { + print $f $var, ",", $val, "\n"; } - close($FILE); + + close($f); } } |