#! /bin/bash
time=60
out=$(cat /proc/net/dev |tr ':' ' '|awk '/eth0/{print $10}')
sleep $time
while : ; do
out1=$(cat /proc/net/dev |tr ':' ' '|awk '/eth0/{print $10}')
out_diff=$((out1-out))
echo "traffic is: $((out_diff/time/1000/1000*8))"
out=$out1
sleep $time
done
#!/usr/bin/perl -w
use strict;
my $time=60;
my $command = "awk -F'[: ]+' 'NR>2&&/eth0/{print \$11}' /proc/net/dev";
my $out=`$command`;
my $out1;
my $result;
my $out_diff;
my $msg;
sub b_print{
if (@_ > 0) {
system("echo $_[0]");
}
}
sleep($time);
while(1) {
$out1 = `$command`;
$out_diff = $out1 - $out;
$result = $out_diff*8/$time/1024/1024;
$msg = "traffic is:$result";
b_print($msg);
$out = $out1;
sleep($time);
}
阅读(837) | 评论(1) | 转发(0) |