Custom Search

Apache web server log rotation script








#!/bin/sh
#written by brent kevin krkosska
/bin/chattr -a /apache/logs/access_log ;
/bin/chattr -a /apache/logs/error_log ;
/apache/bin/httpd -k stop;
/bin/sleep 3;

#note that those are forward ticks, not single quotes:
mv /apache/logs/access_log /apache/logs/access_log.`date|awk '{print $3 $2 $6}'`.`hostname`;
mv /apache/logs/error_log /apache/logs/error_log.`date|awk '{print $3 $2 $6}'`.`hostname`;
touch /apache/logs/access_log /apache/logs/error_log;

#set restrictive permissions on the new log files:
chmod 600 /apache/logs/*_log;

# this line is more LIDS-friendly than apachectl:
/apache/bin/httpd -k start;

# chattrization:
/bin/chattr +a /apache/logs/access_log ;
/bin/chattr +a /apache/logs/error_log ;

#optional sleep to give things time to finish:
sleep 600

#my `hostname` ends with .com; adjust if yours doesn't
#bzip2 would save space, but gzip is winzip9 compatible:
for f in /apache/logs/*.com; do gzip -9 $f; done;
chmod 400 /apache/logs/*.gz ;











www.fiveanddime.net








Custom Search