#!/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;