Merging logrotate'd files back again

As you may already know, logrotate is an excellent utility to keep the size of your log directory under certain control. However in some cases it may be feasible to „undo” the rotated logs into a single monolithic file. Such is a case when you want to migrate your web server log analization from webalizer to awstats. Fortunately there is an utility called mergelog that can this for you for a specific set of files. All I had to do was this small shell wrapper around mergelog to have a complete log directory (containing many virtual host logfiles from apache) „anti-logrotated” into the current working directory.

#!/bin/bash
 
if [ ! -d "$1" ]; then
        echo "usage: $0 [directory]"
        exit -1
fi
 
ls -1 "$1" | sed 's/[.]gz$//g' | sed 's/[.][0-9]*$//g' | sort | uniq | while read logname; do
 
        echo "merging files of ${logname}..."
        zmergelog "$1/${logname}"* > "${logname}"
 
done