2014-12-04 116 views
3

我有兩個logrotate的文件:我卡在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-日產量..

如果我從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 /日誌/ 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)。

Thx提前。

+1

您的重定向在這些行中不正確。他們不會將錯誤信息輸出到這些文件。重定向順序很重要。你想要'>/tmp/logrotate_size 2>&1'。你有沒有嘗試完整路徑在cron條目中登錄? – 2014-12-04 15:45:50

+0

不,我不會,現在我會這樣做 – 2014-12-04 15:50:17

+0

ffs,m8,你是我的保護者))thx很多,我甚至沒有這樣想過 – 2014-12-04 15:59:04

回答

3

您的重定向在這些cron行中不正確。他們不會將錯誤信息輸出到這些文件。

重定向順序很重要。你想>/tmp/logrotate_size 2>&1得到你想要的。

此處的根本問題是信息頁面的「調試crontab」部分所涵蓋的內容之一。

即「做出關於環境的假設」。

對環境

圖形程序(X11應用程序),Java程序,ssh和須藤製作的假設是衆所周知的問題作爲cron作業運行。這是因爲它們依賴於交互式環境中可能不存在於cron環境中的東西。

要更加緊密地模型的cron環境交互,運行

ENV -i SH -c「yourcommand」

這將清除所有環境變量和運行SH這可能是功能的更多微薄您當前shell 。

發現這樣的常見問題:

富:找不到命令或只是富:未找到。

很可能$ PATH在您的.bashrc或類似的交互式init文件中設置。嘗試按完整路徑指定所有命令(或將source〜/ .bashrc放在您嘗試運行的腳本的開頭)。