Morgen zusammen ;)
Ach natürlich mit while, wie auch sonst :P
Hatte gestern nur matsch im kopf, war einfach zu schwül hier ^^
Also ich habs jetzt soweit das ich zumindest schonmal die rausschmeissen kann die nicht im selben monat sind.. Zwar toll und schon ein schritt nach vorne, aber ich will ja alle einträge löschen die
älter sind als einen monat, bei meinem script bekomm ich beim monatswechsel probleme :/
Ich hab gerad ma nach nem cpan kalender modul geschaut, aber bevor ichs testen konnte stellte ich schon fest das ich auf dem system keinerlei module installieren kann, bzw darf.
script:
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
#!/usr/bin/perl
#
# AIX wtmp Cleaner
#
###################
use strict;
use warnings;
my $tmpfile = '/tmp/wtmp.ascii';
my $regex = qr/((?:\w{3}\s+){2}\d+\s+(?:\d+:){2}\d\d\s+[A-Z]{3}\s+\d{4})$/;
my $date = `date`;
my @cdate = split(/ /, $date);
my $cmonth = mapmonth($cdate[1]);
sub bin2ascii {
system("/usr/lib/acct/fwtmp < ./wtmp_testfile > /tmp/wtmp.ascii");
}
sub ascii2bin {
system("/usr/lib/acct/fwtmp -ci < /tmp/wtmp.ascii > ./wtmp_testfile");
}
sub mapmonth {
my %mnr=('Jan', 1, 'Feb', 2, 'Mar', 3, 'Apr', 4, 'Mai', 5, 'Jun', 6, 'Jul', 7, 'Aug', 8, 'Sep', 9, 'Oct', 10, 'Nov', 11, 'Dec', 12);
my $monat=$mnr{$_[0]};
return($monat);
}
sub ripdates {
my $date = `date`;
my @date_now = split(/ /,$date);
my $currentmonth = $date_now[1];
my $mappedmonth = mapmonth($currentmonth);
open my $fh, '<', $tmpfile or die $!;
unlink "wtmpfile.new";
while(my $line = <$fh>) {
foreach ($line) {
my @regexped = ($line =~ $regex);
my @datestring = split(/ /,$regexped[0]);
my $daynr = $datestring[0];
my $monthnr = mapmonth($datestring[1]);
if ($monthnr eq $cmonth) {
open(NEWWTMP,">>wtmpfile.new");
print NEWWTMP $_;
print ("Month: $cmonth -> $line\n");
}
}
}
close $fh;
close (NEWWTMP);
}
print("Loesche wtmp Eintraege der letzten 4 Wochen...\n");
bin2ascii();
ripdates();
#ascii2bin();
#unlink $tmpfile;
#unlink wtmpfile.new;