#!/usr/bin/microperl my $sec2log = 600; while (1) { ########## Gps log rotate ########### open(GPS, "/gps.log"); my @gps = <GPS>; close(FILE); my $togz; my $tolog; my $time = time(); foreach my $line (@gps) { my @split = split(/\|/, $line); $split[1] =~ s/ //g; if (($time - $split[1]) > $sec2log) { $togz .= $line; } else { $tolog .= $line; } } if ($togz) { open(FILE, ">/root/logs/gps-$time.log"); print FILE $togz; close(FILE); `gzip /root/logs/gps-$time.log`; } open(FILE, ">/gps.log"); print FILE $tolog; close(FILE); ########## End ########### sleep($sec2log); }