本文介绍了如何每小时运行一次logrotate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个program.conf,它在EC2实例中每小时对日志进行一次日志旋转。我强制执行命令时,logrotate效果很好(通过 sudo logrotate program.conf --verbose --force ),但它并非每小时运行一次。

I created a program.conf that logrotate my logs hourly in an EC2 instance. the logrotate works well when i force it command (by sudo logrotate program.conf --verbose --force) but it doesn't run each hour.

我通过搜索这个问题来尝试了几种解决方案,例如将program.conf放在/etc/logrotate.d中,并将logrotate从cron.dail移到cron.hourly。
但它不起作用。

I tried several solutions by googling this problem like puting my program.conf in /etc/logrotate.d and moving logrotate from cron.dail into cron.hourly.but it doesn't work.

这是我的program.conf:

Here is my program.conf :

/home/user_i/*.log{
hourly
missingok
dateext
rotate 1
compress
size 100M
sharedscripts
postrotate
    /usr/bin/bash file.sh
endscript
}

有什么想法吗?

谢谢

推荐答案

您将需要在crontab中添加作业

You will need to add the job in your crontab

crontab -e

然后添加一个每小时运行14分钟的作业,

And then add a job that runs every hour 14 minutes past,

14 * * * * /usr/sbin/logrotate /home/sammy/logrotate.conf --state /home/sammy/logrotate-state

来自:

还要另外检查crontab是否确实在运行

Also additionally check if the crontab is actually running by doing

service crontab status

如果已停止,则可以执行此操作

if it is stopped you can start it by doing

service crontab start

这篇关于如何每小时运行一次logrotate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-08 00:27