Simple log-rotator

Non-compressing log-rotator:

# more logrotate.sh
#!/bin/bash
for file in $*
do
mv ${file}.5 ${file}.6
mv ${file}.4 ${file}.5
mv ${file}.3 ${file}.4
mv ${file}.2 ${file}.3
mv ${file}.1 ${file}.2
mv ${file} ${file}.1
touch ${file}
pkill -1 syslog
done

Compressing version:

#!/bin/bash
for file in $*
do
mv ${file}.5.gz ${file}.6.gz
mv ${file}.4.gz ${file}.5.gz
mv ${file}.3.gz ${file}.4.gz
mv ${file}.2.gz ${file}.3.gz
mv ${file}.1.gz ${file}.2.gz
mv ${file} ${file}.1
touch ${file}
pkill -1 syslog
gzip ${file}.1
done

Usage:

# logrotate.sh asa1.log cisco2.log templog
#

Leave a Reply

Your email address will not be published. Required fields are marked *