编写一个 bash 脚本来清空 apache 日志

Mit*_*one 1 linux bash

我有两个目录(~/www/ 和 ~/client-sites/),其中包含一堆站点,每个站点都有 access.log 和 error.log 文件。

找到所有这些文件并清空其内容的最简单方法是什么?它们增长很快,所以我想每个月左右清除一次日志。

fue*_*ero 9

安装 logrotate(Windows 见http://sourceforge.net/projects/logrotatewin):

# CentOS/RHEL
yum install logrotate
# Debian/Ubuntu
apt-get install logrotate
Run Code Online (Sandbox Code Playgroud)

Create/Edit /etc/logrotate.d/httpd,示例取自 CentOS,其他发行版需要调整。

/var/log/httpd/*_log {
    weekly
    missingok
    rotate 5
    compress
    delaycompress
    notifempty
    create 640 root adm
    sharedscripts
    postrotate
        /etc/init.d/httpd reload > /dev/null
    endscript
}
Run Code Online (Sandbox Code Playgroud)