Created
December 30, 2019 08:46
-
-
Save seasonedgeek/2100a47c2f187b2bdaad13eab7fd1eae to your computer and use it in GitHub Desktop.
Script removes yesterday's terminal generated session log files.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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