|< 1 2 3 4 >| | 37 Einträge, 4 Seiten |
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 44
#!/usr/bin/perl use strict; my $filespath = "/home/re17830/chksize/checksize_db"; my $date = `date +%y-%m-%d`; my $day = `date +%d`; my $predaycheck = $date--; my $preday = $day--; my $month = `date +%m`; my $premonth = $month--; if ($month == 01) { $premonth = "12"; } chomp(my $prechk = `echo $preday |wc -ck`); if ($prechk == 2) { $preday = "0$predaycheck"; } my $pre_date = "`date +%y-%m`-$preday"; my $newfile = "$filespath/SizeCheck-$date\.dat"; my $oldfile = "$filespath/SizeCheck-$pre_date\.dat"; my @filesystem = `ls -Rlgo /`; open(REWRITE, ">$newfile"); foreach(@filesystem) { 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"; } else { next; } } if ($day == 28) { `rm $filespath/SizeCheck-*-\$premonth\-*`; }
Quotextest11 # perl build_checksize_db.pl
sh[2]: 0403-057 Syntax error at line 2 : `|' is not expected.
xtest11 #
chomp(my $prechk = `echo $preday |wc -ck`);
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
#!/usr/bin/perl use strict; use warnings; use Date::Calc qw(AddDeltaDays AddDeltaYM); my $filespath = "/home/re17830/chksize/checksize_db"; my ($day,$month,$year) = (localtime time)[3..5]; my $date = sprintf "%02d-%02d-%02d", $year % 100, $month+1, $day; my ($pyear,$pmonth,$pday) = Add_Delta_Days( $year+1900,$month+1,$day, -1 ); my ($lyear,$lmonth,$lday) = Add_Delta_YM( $year+1900, $month+1, $day, 0, -1 ); my $predate = sprintf "%02d-%02d-%02d", $pyear % 100, $pmonth, $pday; chomp(my $prechk = `echo $pday | wc -ck`); if ($prechk == 2) { $preday = "0$predaycheck"; } my $newfile = "$filespath/SizeCheck-$date\.dat"; my $oldfile = "$filespath/SizeCheck-$predate\.dat"; my @filesystem = `ls -Rlgo /`; open(REWRITE, ">$newfile"); foreach(@filesystem) { 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"; } else { next; } } if ($day == 28) { `rm $filespath/SizeCheck-*-\$premonth\-*`; }
1
2
3
4
5
6
7
8
9
10
11
12
# Wenn der Tag einstellig ist, muss eine 0 vorangestellt werden.
if [ $(echo $PREDAYCHECK | wc -ck) -eq 2 ] ; then
PREDAY=0$PREDAYCHECK
else
PREDAY=$(($DAY -1))
fi
# Wenn das Script am 1. des Monats ausgeführt wird,
# vergleiche das Filesystem mit dem 28. des vor-Monats.
if [ $DAY -eq 1 ] ; then
PREDAY=28
fi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
chomp(my $day = $ARGV[1]);
chomp(my $month = `date +%m`);
chomp(my $premonth = $month--);
if ($month == 01) {
$premonth = 12;
}
chomp(my $year = `date +%y`);
print ("year-1: $year\n");
chomp(my $preyear = $year--);
print ("year-2: $year\n");
my $file = "$filespath\SizeCheck-$year\-$month\-$day\.dat";
print ("File: $file\n");
1
2
3
4
xtest11 # ./checksize.pl /home 11
year-1: 08
year-2: 7
File: /home/re17830/chksize/checksize_db/SizeCheck-7-0-11.dat
1 2 3 4
my $year = "08"; $year--; print "Test1: $year\n"; print "Test2: ", sprintf( "%02d", %year),"\n";
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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
#!/usr/bin/perl use strict; my $filespath = "/home/re17830/chksize/checksize_db/"; if (defined $ARGV[0]) {} else { print("Error: No argument\n\nUsage: checksize <path> <day>\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 = <TMP>; 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 @$_; }
Quote
|< 1 2 3 4 >| | 37 Einträge, 4 Seiten |