Created
May 9, 2018 16:35
-
-
Save grahamgilbert/9ae1ea78add169aca6cfecdfd168cd36 to your computer and use it in GitHub Desktop.
Revisions
-
grahamgilbert created this gist
May 9, 2018 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,43 @@ #!/usr/bin/python """ Removes cached apple updates that are older than 24 hours """ import datetime import os import shutil import sys def main(): """ Main event """ update_dir = '/Library/Updates' # If the directory isn't there, might as well exit if not os.path.exists(update_dir): sys.exit() now = datetime.datetime.now() day_ago = now - datetime.timedelta(hours=24) # Get all directories in /L/Updates for item in os.listdir(update_dir): if item == 'PreflightContainers': continue if os.path.isdir(os.path.join(update_dir, item)): modification_time = datetime.datetime.fromtimestamp( os.stat(os.path.join(update_dir, item)).st_mtime) if modification_time < day_ago: # This is ick, but we would rather eat the error than # halt the Munki run try: shutil.rmtree(os.path.join(update_dir, item)) except Exception: pass if __name__ == '__main__': main()