Program suggestion

David Nicol davidnicol at gmail.com
Tue Nov 8 14:11:53 CST 2005


On 11/8/05, Sexton, Kyle <ksexton at gsihosting.com> wrote:
> Oh, I just ran into something where a small utility would help out.  Basically I needed something that would be just like cp or mv, but would give the transfer rate of the file copy.  Lot's of programs do this (scp, ftp, wget, etc...), but I don't think there is a way to have cp do it.  I could use 'time', but that's no fun. :)
>
> Kyle Sexton

#!/usr/bin/perl
($source,$dest) = @ARGV;
open S, "<$source" or die "opening $source for read: $!";
open D, ">$dest" or die "opening $dest for write: $!";
$time = time();
while(<S>){
    $count++;
    $bytes += length($_);
    print '.';
    if ($time != time()){
        print "\n$count lines ($bytes chars) per second\n";
        $bytes = $count = 0;
        $time = time();
    };
    print D $_;
};
print "\n";
__END__

plenty of opportunities for fun in extending that :)


--
David L Nicol
A room without books is perfect for watching television


More information about the Kclug mailing list