小编San*_*S T的帖子

使用 perl Logfile::Rotate 进行日志旋转

以下脚本在 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;
Run Code Online (Sandbox Code Playgroud)

size logrotate perl

2
推荐指数
1
解决办法
1206
查看次数

标签 统计

logrotate ×1

perl ×1

size ×1