Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Restricting Size of log files

Status
Not open for further replies.

user2base

Technical User
Oct 16, 2002
29
0
0
GB
I've got a script that opens a log file and write into it.
I would like this file not to exceed a certain limit (500 lines for instances) i.e if I had line #501 line it's going to remove line #1 and so on...

Is there a nice way to achieve that ?

 
Since your are using lines instead of actual filse size this is a sinch.

$new = "new_log_entry";
open (TXTFILE, "> /html/Inserts/FOOTER.txt")||die "Cannot open HEADER.txt file:$!: ./html/Inserts/HEADER.txt";
@lines = <TXTFILE>;


if ($#lines >= 500){
$x = shift(@lines);
push (@lines ,$new_entry);
} else { push (@lines ,$new_entry);}
foreach $item (@lines){
print TXTFILE $item;
}
close(TXTFILE);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top