forked from ttsiodras/utils
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspeed.pl
More file actions
executable file
·38 lines (35 loc) · 908 Bytes
/
Copy pathspeed.pl
File metadata and controls
executable file
·38 lines (35 loc) · 908 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/perl -w
#
# If you are downloading a file via youtube-dl or FTP or SCP or
# any other fancy protocol, this script can act as a progress
# and speed indicator - just
#
# speed.pl filename
#
# ...and you'll see.
#
use strict;
die "Usage: $0 filename\n" unless @ARGV == 1;
die "$ARGV[0] is not a file!\n" unless -f $ARGV[0];
my $oldSize = -s $ARGV[0];
my $noData = 0;
my $cnt = 0;
my $total = 0;
while (1) {
sleep(1);
$cnt++;
my $newSize = -s $ARGV[0];
$total += $newSize - $oldSize;
print sprintf("Size: %12u bytes, speed: %12u bytes/sec (avg: %12u bytes/sec)\n", -s $ARGV[0], $newSize-$oldSize, int($total/$cnt));
if ($newSize == $oldSize) {
$noData++;
print "Stalling... Waiting for $noData seconds...\n";
sleep($noData);
if ($noData == 10) {
die "No data received for 55 seconds...\n";
}
} else {
$noData = 0;
}
$oldSize = $newSize;
}