WWW Monthly Log Rotation Set Up

Automatic monthly Apache log rotation was set up on the main web server, www.ups.edu.

A shell script called logrotate.sh was written that will move the access, error and ssl logs to /web/logs and write its output to /var/log/logrotate.log

logrotate.sh resides in /usr/local/apache/logs

source of script is:

mv /usr/local/apache/logs/access_log /web/logs/access_log`date +%Y-%m-%d`
mv /usr/local/apache/logs/error_log /web/logs/error_log`date +%Y-%m-%d`
mv /usr/local/apache/logs/ssl_engine_log /web/logs/ssl_engine_log`date +%Y-%m-%d`
mv /usr/local/apache/logs/ssl_request_log /web/logs/ssl_request_log`date +%Y-%m-%d`
/usr/local/apache/bin/apachectl graceful

The moved files will have a date in their names – an example of the format should be:


The year (in this case 2003) and the month (in this case May [5]) will change, but the day (1) will not. Rotation will always be at midnight on the first day of every month.

The last line allows apache to be restarted without interaction from the command line.

This script has been inserted into the crontab for root.