我有两个logrotate文件:
/etc/logrotate.d/nginx-size
/var/log/nginx/*.log
/var/log/www/nginx/50x.log
{
missingok
rotate 3
size 2G
dateext
compress
compresscmd /usr/bin/bzip2
compressoptions -6
compressext .bz2
uncompresscmd /usr/bin/bunzip2
notifempty
create 640 nginx nginx
sharedscripts
postrotate
[ -f /var/run/nginx.pid ] && kill -USR1 `cat /var/run/nginx.pid`
endscript
}
和
/etc/logrotate.d/nginx-daily
/var/log/nginx/*.log
/var/log/www/nginx/50x.log
{
missingok
rotate 3
dateext
compress
compresscmd /usr/bin/bzip2
compressoptions -6
compressext .bz2
uncompresscmd /usr/bin/bunzip2
notifempty
create 640 nginx nginx
sharedscripts
postrotate
[ -f /var/run/nginx.pid ] && kill -USR1 `cat /var/run/nginx.pid`
endscript
}
命令logrotate -d -v /etc/logrotate.d/nginx-size
输出:
reading config file /etc/logrotate.d/nginx-size
compress_prog is now /usr/bin/bzip2
compress_options is now -6
compress_ext is now .bz2
uncompress_prog is now /usr/bin/bunzip2
Handling 1 logs
rotating pattern: /var/log/nginx/*.log
/var/log/www/nginx/50x.log
2147483648 bytes (3 rotations)
empty log files are not rotated, old logs are removed
considering log /var/log/nginx/access.log
log does not need rotating
considering log /var/log/nginx/error.log
log does not need rotating
considering log /var/log/nginx/get.access.log
log does not need rotating
considering log /var/log/nginx/post.access.log
log needs rotating
considering log /var/log/www/nginx/50x.log
log does not need rotating
rotating log /var/log/nginx/post.access.log, log->rotateCount is 3
dateext suffix '-20141204'
glob pattern '-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
glob finding old rotated logs failed
renaming /var/log/nginx/post.access.log to /var/log/nginx/post.access.log-20141204
creating new /var/log/nginx/post.access.log mode = 0640 uid = 497 gid = 497
running postrotate script
running script with arg /var/log/nginx/*.log
/var/log/www/nginx/50x.log
: "
[ -f /var/run/nginx.pid ] && kill -USR1 `cat /var/run/nginx.pid`
"
compressing log with: /usr/bin/bzip2
ngnix-daily上的相同(正常)输出..
如果我从root命令运行
logrotate -f /etc/logrotate.d/nginx-size
手动,它做了所有的事情。但!它不会自动运行!
contab:
*/5 5-23 * * * root logrotate -f -v /etc/logrotate.d/nginx-size 2>&1 > /tmp/logrotate_size
00 04 * * * root logrotate -f -v /etc/logrotate.d/nginx-daily 2>&1 > /tmp/logrotate_daily
另外,files / tmp / logrotate_daily& / tmp / logrotate_size始终为空..
Cron不会在/ var / log / cron
中给我任何错误Dec 4 14:45:01 (root) CMD (logrotate -f -v /etc/logrotate.d/nginx-rz-size 2>&1 > /tmp/logrotate_size )
Dec 4 14:50:01 (root) CMD (logrotate -f -v /etc/logrotate.d/nginx-rz-size 2>&1 > /tmp/logrotate_size )
dat有什么问题?Centos 6.5 x86_64,Logrotate版本3.8.7(源代码内容)+ logrotate版本3.7.8(通过rpm)。
提前谢谢。答案 0 :(得分:3)
您的重定向在那些cron行中不正确。他们不会将错误信息输出到这些文件。
重定向顺序很重要。您希望>/tmp/logrotate_size 2>&1
得到您想要的内容。
这里的根本问题是"调试crontab"所涵盖的事情之一。 cron信息页面的一部分。
即"对环境做出假设"。
对环境做出假设
图形程序(X11应用程序),java程序,ssh和sudo作为cron作业运行是众所周知的问题。这是因为它们依赖于交互式环境中可能不存在于cron环境中的东西。
要以交互方式更密切地模拟cron的环境,请运行
env -i sh -c' yourcommand'
这将清除所有环境变量并运行sh,这可能比当前shell的功能更少。
以这种方式发现的常见问题:
foo:找不到命令或只找到foo:找不到。
很可能在.bashrc或类似的交互式init文件中设置了$ PATH。尝试按完整路径指定所有命令(或将源〜/ .bashrc放在您尝试运行的脚本的开头)。