Automated System Log Purger

This python utility automatically parses directory paths for archived .log or .gz files that are older than a specific retention period (e.g., 30 days) and deletes them to free up disk space.

Features

Python Code

import os
import time

def purge_old_logs(log_dir, age_limit_days=30):
    limit_time = time.time() - (age_limit_days * 86400)
    for root, dirs, files in os.walk(log_dir):
        for name in files:
            file_path = os.path.join(root, name)
            if os.path.getmtime(file_path) < limit_time:
                os.remove(file_path)