Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- # For Archive Team Friendster project
- # http://archiveteam.org/index.php?title=Friendster
- # This script will summarize your bff.sh's download progress with the
- # latest finished ID and percent complete for each instance as well as overall
- # percentage done, and even mini-progress bars! (screenshot: imgur.com/x2Hhd)
- # You can print the status at any time by running summary.pl, and even
- # write a little loop to run it every minute so you always have a little
- # up-to-date status window:
- # $ while [ ! -e STOP ]; do ./summary.pl; sleep 60; done;
- # The requirement is that you have a file "progress.txt" where your
- # bff.sh scripts log their finished profile IDs. For advanced stuff like
- # percent complete and progress bars, you also need a file "config.txt" where
- # information on your instances' starting configurations is stored. invoker.pl
- # can set up both for you (pastebin.com/HXtSDi42) or you do it yourself. For
- # "progress.txt" you just add a line to the loop that runs your bff.sh
- # instances: 'echo "#: $i" >> progress.txt' where "#" is the number of the
- # instance and $i is the profile ID it just finished. Whatever you do is fine
- # as long as it adheres to the format "[instance number]:[profile id]"
- # (whitespace ignored) and your instances append a line for every profile id
- # they finish. For "config.txt" it's simply a file with a line for each
- # instance saying which ID it started on, in the same format as "progress.txt":
- # "[instance number]:[starting profile id]" (whitespace ignored)
- sub trim {
- my $string = shift;
- $string =~ s/^\s+//;
- $string =~ s/\s+$//;
- return $string;
- }
- my $logfile = "progress.txt";
- my $confile = "config.txt";
- my $config = (-e $confile);
- # You can also use a custom filename instead of progress.txt, given as an
- # argument: $ ./summary.pl yourfile.txt
- if (@ARGV > 0) {
- $logfile = shift @ARGV;
- }
- open FILEIN, "<", $logfile or die "Could not open logfile: $!";
- if ($config) {
- open CONFIG, "<", $confile or warn "Could not open config file: $!";
- }
- # Reads the current file, stores the latest figures in a hash
- my %stats;
- my @fields;
- foreach my $line (<FILEIN>) {
- @fields = split ":", $line;
- if (@fields == 2) {
- chomp($fields[1]);
- $stats{trim($fields[0])} = trim($fields[1]);
- }
- }
- # Yeah, kinda kludgy but I was impatient and it's surprisingly hard to delete
- # a file using the same filehandle you just read from
- close FILEIN;
- open FILEOUT, ">", $logfile or die "Could not open logfile: $!";
- my %begins;
- if ($config) {
- foreach $line (<CONFIG>) {
- @fields = split ":", $line;
- if (@fields == 2) {
- chomp($fields[1]);
- $begins{trim($fields[0])} = trim($fields[1]);
- }
- }
- }
- my $range = $begins{2} - $begins{1};
- if (defined $range && $range < 1) { $range = 1 }
- # Prints the values from the hash to the screen and back to the file
- my @inst = sort {$a <=> $b} keys %stats;
- my $lineout;
- my $pct;
- my $pctsum = 0;
- my $bar;
- foreach my $inst (@inst) {
- $lineout = sprintf("%2d: %d", $inst, $stats{$inst});
- print FILEOUT "$lineout\n";
- print $lineout;
- if ($config) {
- $pct = 100 * ($stats{$inst} - $begins{$inst} + 1)/$range;
- $pctsum += $pct;
- $bar = "=" x ($pct/7);
- printf " %3d%%", $pct;
- print " $bar\n";
- } else {
- print "\n";
- }
- }
- # Overall percent done for all instances
- printf "total: %3d%%\n", $pctsum/@inst;
- close FILEOUT;
- close CONFIG;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement