#!/usr/local/bin/perl

$log = '/logs/down.log';
$file = 'http://example.com/file.zip';

open (CNT,"+<$log") || &endIt;
flock (CNT,2); seek (CNT,0,0);
@inFile = <CNT>;

($count,$eol) = split(/\|/,$inFile[0]);
    $count++;
    $inFile[0] = join ("\|",$count,"\n");

@outFile = sort {($b =~ /(\d+)/)[0] <=> ($a =~ /(\d+)/)[0]} @inFile;

seek (CNT,0,0);
print (CNT @outFile);
truncate (CNT,tell(CNT)); close (CNT);

	print "Content-type: text/html\n";
	print "Location: $File\n\n";

exit;

sub endIt # exit on error
{ exit;
} # end endIt
Published in: CGI
Download

Related snippets