我有两个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-sizeoutput:
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
如果我从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
另外,文件/ 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).
提前谢谢.
重定向顺序很重要.您想要> / tmp / logrotate_size 2>& 1获得所需的内容.
这里的根本问题是cron信息页面的“调试crontab”部分涵盖的内容之一.
即“对环境做出假设”.
@H_301_76@Making assumptions about the environment
Graphical programs (X11 apps),java programs,ssh and sudo are notorIoUsly problematic to run as cron jobs. This is because they rely on things from interactive environments that may not be present in cron’s environment.
To more closely model cron’s environment interactively,run
env -i sh -c ‘yourcommand’
This will clear all environment variables and run sh which may be more meager in features that your current shell.
Common problems uncovered this way:
foo: Command not found or just foo: not found.
Most likely $PATH is set in your .bashrc or similar interactive init file. Try specifying all commands by full path (or put source ~/.bashrc at the start of the script you’re trying to run).