Wednesday, July 4, 2012

logrotate: rotating logs in multiple directories

logrotate: rotating logs in multiple directories: I've got a server with almost one hundred web-sites. Each of the sites is in its own directory and runs its own logs ...

 logrotate.conf:
include /usr/local/etc/logrotate.d
Only one hour later I understood that I can just write a path with multiple meta-characters to include ALL logs in just one line:
/usr/local/www/*/logs/*.log {
    daily
    rotate 60
    compress
    notifempty
    postrotate
          [ ! -f /var/run/nginx.pid ] || kill -USR1 `cat /var/run/nginx.pid`
    endscript

}

More than one 'exec' action in 'find' command

More than one 'exec' action in 'find' command: When you run find command, you can pass the names of the found files to an arbitrary command using -exec option: find /tmp -mtime +3 -exe...

find /tmp -mtime +3 -exec rm {} \;
find /tmp -mtime +3 -exec sh -c 'ls -ld "$0"; rm "$0"' {} \;