For no reason at all, I needed a simple trimmer program. Rather than write a shell script in bash, thought to do it in python.
#!/usr/bin/python # run by crontab # removes any files in /tmp/ older than 7 days import os, sys, time from subprocess import call now = time.time() cutoff = now - (7 * 86400) files = os.listdir("/tmp") for xfile in files: if os.path.isfile( "/tmp/" + xfile ): t = os.stat( "/tmp/" + xfile ) c = t.st_ctime # delete file if older than a week if c < cutoff: os.remove("/tmp/" + xfile)
Save this as /wherever/trim_tmp.py, and chmod +x it for good measure. Then, add to crontab with crontab -e. In the localized user crontab file, put @daily /wherever/trim_tmp.py