Saturday 11 December 2010

cleaning frequency of /tmp and /var/tmp

/tmp normally gets cleared after every reboot on ubuntu which is a bit quick for me. For example I sometimes want to save a screenshot and maybe quickly edit it and e-mail it, but I don't want to loose it if my system reboots for whatever reason (including forgetting that I was busy with something).
It turns out that you can set how long to keep stuff in /tmp by setting TMPTIME in /etc/default/rcS to the number of days to keep stuff (I'm going for 7days now).
http://linuxers.org/article/differences-between-tmp-and-vartmp

Apparently you normally should put temp stuff you want to keep a bit longer in /var/tmp [1] but that does not seem to get cleared out regularly.
So I made a weekly cronjob to clean out stuff older than 60 days:/etc/cron.weekly/clean_var_tmp.sh
#!/bin/bash
days=60
tmpdir=/var/tmp/
find -P ${tmpdir} -type f -mtime +$days        -exec su amanica -c "notify-send 'weekly clean ${tmpdir}' 'rm {}'" \; -exec rm {} \;
find -P ${tmpdir} -type d -mtime +$days -empty -exec su amanica -c "notify-send 'weekly clean ${tmpdir}' 'rm {}'" \; -exec rm -r {} \;

http://ubuntu-virginia.ubuntuforums.org/showthread.php?t=1524077

[1] http://www.pathname.com/fhs/2.2/fhs-5.15.html