-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile-eta.pl
More file actions
executable file
·44 lines (38 loc) · 1.1 KB
/
file-eta.pl
File metadata and controls
executable file
·44 lines (38 loc) · 1.1 KB
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
39
40
41
42
43
#!/usr/bin/env perl
# Watches the numer of lines in a file grow and monitors rate
# If a goal (numer of lines is given) and ETA will also be printed
use strict;
use warnings;
use Utils;
my $file = shift;
-r $file or die("Please provide path to (readable) file to be monitored\n");
my $goal = shift || 0;
my $resolution = shift || 30; # seconds
my $prev;
my $curr;
my $rate;
my @parts;
for ($prev=nlines($file); sleep($resolution); $prev=$curr) {
$curr = nlines($file);
# Enforce float arithmetic
$rate = 1.0 * ($curr - $prev) / $resolution;
next unless $rate;
@parts = localtime();
printf "%02d:%02d:%02d Rate: %10.3f /s", @parts[2,1,0], $rate;
if ($goal) {
my $lines = $goal - $curr;
if ($lines < 0) {
printf "\nLines: %10d\n", $curr;
exit;
}
my $remain = $lines / $rate;
@parts = gmtime($remain);
# Add days to hours field
$parts[2] += $parts[7]*24;
printf
"\tRemaining: lines: %10d , time: %02d:%02d:%02d",
$lines, @parts[2,1,0];
}
print "\n";
$prev = $curr;
}