OLW: Print gzipped, logrotated files together

Looking for #oneliners to scan some log files in #bash on #Linux that are automatically logrotated and gzipped along with the currently running log which is unzipped? This is a script that will print them all together so that you can pipe it to some custom grep/awk/sed logic to scan for information across your current and old logs simultaneously.

Put this logic in a file called xcat.sh (and of course give it execute permission):

for i in $@;do
[ ! -z “$(file -i $i | grep “gzip”)” ] && zcat $i || cat $i
done

Use it like so to scan all nginx logs:
$ ./xcat.sh /var/log/nginx/access.log*

“Fish and visitors smell in three days.” – Benjamin Franklin

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s