Hallo,
ich habe ein problem mit einer logdatei die mit einem perlscript
aktualisiert wird.Vorher gings halbwegs mit einem DB_File (ausser dass der eintrag datum nicht aktualisiert wurde) jedoch möchte ich anstatt DB eine text
file zum loggen haben.Das script bzw. das problem sieht folgend aus:
my $ag_now = length($ENV{'HTTP_USER_AGENT'}) || '10';
open(LOG, "+>$loginlog") || die "cant open log\n";
flock(LOG,LOCK_EX) || die "cant flock\n";
print LOG "9*0*Jul 10 $username\n" || die "cant print\n";#hab ich nur zum testen
my ($ag_last,$count_last,$date_last) = split(/\*/,$logins{$username});#mit logins gibts probleme
#if first time logging in today
if ($date_last ne $date_today)
{
$count_last=0;
}
elsif ($ag_last ne $ag_now)
{
$count_last++;#in der textdatei zählt der eintrag $count_last nicht hoch?!
seek (LOG, 0, 5); #der eintrag soll immer neu überschrieben werden nicht neu.
$logins{$username} = ("$ag_now*$count_last*$date_today");#hier auch,wie kann ich den eintrag aktualisieren?
print LOG "$ag_now*$count_last*$date_today $username\n" || die "cant print\n";
fehlermeldung des servers ist
Use of uninitialized value in string ne at test.cgi line...damit ist if ($date_old ne $date_today) gemeint.
im DB model sah es so aus:
use DB_File;
my $ag_now = length($ENV{'HTTP_USER_AGENT'}) || '10';
my %logins;
my $db = (tie %logins , 'DB_File', "$loginlog", O_RDWR|O_CREAT, 0644);
my $fd = $db->fd;
open(DB_FH, "+<&=$fd");
flock (DB_FH,LOCK_EX);
while (<DB_FH>){
if (!/$username/){
$logins{$username} = "$ag_now*1*$date_today"; #prüft ob der eintrag schon drinn ist
}
}
($ag_last,$count_last,$date_last) = split(/\*/,$logins{$username});
#if first time logging in today
if ($date_last ne $date_today)#der eintrag datum wird aber nicht aktualisiert in der DB
{
$count_last=0;
}
elsif ($ag_last ne $ag_now)
{
$count_last++;
$logins{$username} = ("$ag_now*$count_last*$date_today");
Gruss vom
Alain