#!/usr/bin/perl use strict; my $filespath = "/home/re17830/chksize/checksize_db/"; if (defined $ARGV[0]) {} else { print("Error: No argument\n\nUsage: checksize \n"); exit 0; } chomp(my $mountpt = $ARGV[0]); chomp(my $day = $ARGV[1]); chomp(my $month = `date +%m`); chomp(my $premonth = ($month -1)); if ($month == 01) { $premonth = 12; } chomp(my $year = `date +%y`); chomp(my $preyear = ($year - 1)); my $file = "$filespath\SizeCheck-$year\-$month\-$day\.dat"; my $monthfile = "$filespath\SizeCheck-$year\-$premonth\-$day\.dat"; my $yearfile = "$filespath\SizeCheck-$preyear\-$premonth\-$day\.dat"; if (-T "$file") {} else { $file = "$monthfile"; } my @fslist = `ls -Rlgo $mountpt`; my $tmpfile = "/tmp/SizeCheck.tmp"; open(REWRITE, ">$tmpfile"); print REWRITE "$mountpt\:\n"; foreach(@fslist) { chomp(); my @line = split(/ +/); if ($line[0] =~ m/^\//g) { print REWRITE "\n$line[0]\n"; } elsif (($line[0] =~ m/^dr/g) || ($line[0] =~ m/^-r/g)) { print REWRITE "$line[2]\t\t$line[6]\n"; } } my $tmp2 = "/tmp/sizecheck.tmp"; system("sdiff $file $tmpfile \|egrep \[\:\\\<\\\>\\\|\] > $tmp2"); open(TMP, "$tmp2"); my @diff = ; sub calcdiff { my $old = shift; my $new = shift; if ($new > $old) { my $ergebniss_1 = ($new - $old); return($ergebniss_1); } elsif ($old > $new) { my $ergebniss_2 = ($old - $new); return ($ergebniss_2); } } my @order; while( my $line = @diff ){ if ( $line =~ m/^(.+):\s+\/.+:$/) { push @order, [$1."\n"]; } elsif ( $line =~ m/(^\d+)\s+(.+)\s+(.)\s+(\d+)\s+(.+)\s+$/ ) { if ($3 eq "\|") { push @{ $order[-1] },"\t$2\t$1\t$4\t" . "Diff: " . &calcdiff("$1","$4") . "\n"; } elsif ($3 eq "\<") { push @{ $order[-1] }, "\tNew File:\t$5\tSize: $4\n"; } elsif ($3 eq "\>") { push @{ $order[-1] },"\tFile deleted:\t$5\n"; } } } for( @order ){ next if @$_ == 1; print $_ for @$_; }