Difference between revisions of "Logrotate trivial"
From Noah.org
Jump to navigationJump to searchm |
m |
||
(One intermediate revision by the same user not shown) | |||
Line 1: | Line 1: | ||
[[Category:Engineering]] | [[Category:Engineering]] | ||
− | == Trivial log rotation script == | + | |
− | This is a trivial log rotator for Apache. | + | = simple example for the Fedora logrotate utility = |
− | Run it from cron monthly to keep 3 months of logs. | + | |
− | This isn't so useful these days as most systems now | + | This is a minimal '''logrotate''' configuration. This will rotate the log file every day for a month (30 days). Put this in '''/etc/logrotate.d/bash-commands''' |
− | have Red Hat's "logrotate" installed by default. | + | <pre> |
+ | /var/log/bash-commands.log { | ||
+ | daily | ||
+ | rotate 30 | ||
+ | delaycompress | ||
+ | compress | ||
+ | notifempty | ||
+ | missingok | ||
+ | nomail | ||
+ | } | ||
+ | </pre> | ||
+ | |||
+ | = Two Trivial Log Rotators = | ||
+ | |||
+ | == General purpose == | ||
+ | |||
+ | This one is not finished and is broken... I was trying to write a one-liner log rotator. | ||
+ | |||
+ | <pre> | ||
+ | #!/bin/sh | ||
+ | |||
+ | # | ||
+ | # This rotates a set of file. | ||
+ | # | ||
+ | maxdays=5;rm -f day${maxdays} ; for i in `seq 1 ${maxdays}`; do num=`expr ${i} - ${maxdays}`;num=`expr ${num} \* -1`;echo "$num";newnum=`expr ${num} + 1`; if [ -f day${num} ]; then mv day${num} day${newnum};fi; done ; touch day1 | ||
+ | </pre> | ||
+ | |||
+ | == Trivial Apache log rotation script == | ||
+ | |||
+ | This is a trivial log rotator for Apache. Run it from cron monthly to keep 3 months of logs. This isn't so useful these days as most systems now have Red Hat's "logrotate" installed by default. | ||
<pre> | <pre> |
Latest revision as of 05:21, 27 March 2014
Contents
simple example for the Fedora logrotate utility
This is a minimal logrotate configuration. This will rotate the log file every day for a month (30 days). Put this in /etc/logrotate.d/bash-commands
/var/log/bash-commands.log { daily rotate 30 delaycompress compress notifempty missingok nomail }
Two Trivial Log Rotators
General purpose
This one is not finished and is broken... I was trying to write a one-liner log rotator.
#!/bin/sh # # This rotates a set of file. # maxdays=5;rm -f day${maxdays} ; for i in `seq 1 ${maxdays}`; do num=`expr ${i} - ${maxdays}`;num=`expr ${num} \* -1`;echo "$num";newnum=`expr ${num} + 1`; if [ -f day${num} ]; then mv day${num} day${newnum};fi; done ; touch day1
Trivial Apache log rotation script
This is a trivial log rotator for Apache. Run it from cron monthly to keep 3 months of logs. This isn't so useful these days as most systems now have Red Hat's "logrotate" installed by default.
#!/bin/sh ################################################ LOG_PATH=/var/www/logs APACHECTL=/var/www/apache2/bin/apachectl ################################################ cd $LOG_PATH mv -f access_log_1.gz access_log_2.gz mv -f access_log access_log_1 gzip access_log_1 touch access_log chmod 644 access_log mv -f error_log_1.gz error_log_2.gz mv -f error_log error_log_1 gzip error_log_1 touch error_log chmod 644 error_log mv -f ssl_request_log_1.gz ssl_request_log_2.gz mv -f ssl_request_log ssl_request_log_1 gzip ssl_request_log_1 touch ssl_request_log chmod 644 ssl_request_log mv -f ssl_engine_log_1.gz ssl_engine_log_2.gz mv -f ssl_engine_log ssl_engine_log_1 gzip ssl_engine_log_1 touch ssl_engine_log chmod 644 ssl_engine_log $APACHECTL graceful 2>&1 >/dev/null