Skip to content

Instantly share code, notes, and snippets.

@seasonedgeek
Created December 30, 2019 08:46
Show Gist options
  • Save seasonedgeek/2100a47c2f187b2bdaad13eab7fd1eae to your computer and use it in GitHub Desktop.
Save seasonedgeek/2100a47c2f187b2bdaad13eab7fd1eae to your computer and use it in GitHub Desktop.
Script removes yesterday's terminal generated session log files.
#!/usr/local/bin/python3
""" Squash Session Logs
This script removes yesterday's terminal generated session log files.
"""
import datetime
import glob
import os
# users path/to/log_files.
TARGET_DIRECTORY = "/Users/tstewart/logs/iterm2/sessions"
# get yesterday's date value, as int(YYYYmmdd)
today = datetime.date.today()
calday = today.strftime("%Y-%m-%d")
calday = calday.replace("-", "")
calnum = int(calday) - 1
# create target file path
target_file_path = TARGET_DIRECTORY + "/" + str(calnum) + "*.log"
# find and remove a partial matching log file
for file_name in glob.glob(target_file_path):
os.remove(file_name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment