以下脚本在 CentOS 上执行时有效,但它不会根据大小轮换日志。每次执行此脚本时都会生成一个新日志。谁能告诉我如何根据大小使这个脚本工作?
#!/usr/bin/perl
use Logfile::Rotate;
my $logfile = new Logfile::Rotate(
File => '/var/log/remotehost/fakepath/Syslog.log',
Count => 100,
Gzip => '/usr/bin/gzip',
size => 1*1024*1024,
sub {
open my $PID, '<', '/usr/lib/systemd/system/rsyslog.service' or
die "Unable to open pid file:$!\n";
chomp(my $pid = <$PID>);
close $PID;
kill 'HUP', $pid;
}
);
# Log file locked (really) and loaded. Now let's rotate it.
$logfile->rotate();
# make sure the log file is unlocked (destroying object unlocks file)
undef $logfile;