#!/usr/bin/perl

use strict;
use Time::Local;

my $path="/var/log/backup";
my ($day)=$ARGV[0] || (localtime(time)=~/^(\w{3})/);

opendir (DIR, $path);

for my $dir (readdir DIR) {
	next unless $dir=~/$day$/;
	
	open (F, "$path/$dir");
	undef my $start;
	undef my $stop;
	for (<F>) {
		next unless /\+\+\+/;
		/(\d\d):(\d\d):(\d\d)/;
		my $seconds=($1*60*60)+($2*60)+$3;
		$stop=$seconds  if $start && !$stop;
		$start=$seconds if !$start && !$stop;

		print;
		if ($start && $stop) {
			my $duration=sprintf("%.2f",($stop-$start)/60);
			print " - $duration minutes\n\n";
			undef $start;
			undef $stop;
		}
	}
	close F;
	
}

closedir DIR;
