Recipe 2Compressing Old Log Files

Task

You’re “on loan” to the operations team—you’re going to help them by writing some utilities. The operations team lead sends you the following email:

Welcome to the team!

Your first task, should you choose to accept it, is to write a “janitor” utility. This utility should go over a given directory and compress any log file (having .log suffix) that is over a month old. After compressing, you should compare the content of the compressed file with the original file (say, using SHA1) and if it matches, delete the original file.

This message won’t destruct in five seconds.

After some back-and-forth, you agree that “a month” equals thirty days and that you’ll use gzip compression.

Shell Magic

I know you can ...

Get Effective Go Recipes now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.