I have folder for temporary folders and I would like it to be emptied automatically at 3am. I know crontab probably could do this but what if my laptop isn't on when it should run?
Asked
Active
Viewed 199 times
1
1 Answers
2
The answer to your problem is Anacron. It comes with Ubuntu by default. Just put your script in one of these folders and make it executable:
/etc/cron.hourly # run hourly, only available since Ubuntu 14.04
/etc/cron.daily # run daily
/etc/cron.weekly # run weekly
/etc/cron.monthly # run monthly
For finetuning check out the anacron manpage. The difference between anacron and crontab is that anacron jobs will run later if they can't run at the specified time.
unlink
. The space occupied by the file is reclaimed only if and when the file is closed by all processes that opened it. This is why you can update the system without rebooting - the daemons refer to the unlinked file until they are restarted and re-open the new file. This also allows an application to safely create a temporary file that will be visible only to it (short of race conditions). That's also why you need to check for unlinked files inlsof
when you run out of space. This behavior is notably different from the Windows one. – ignis Oct 14 '14 at 18:02mount --bind
a subdirectory of /tmp (which is for files and directories that do not have to survive reboot) or mounttmpfs
over that directory (con: makes it possible to run out of memory; no pros with respect to keeping it on the filesystem; which is why Debian and ubuntu do not mount tmpfs on /tmp). I'm answering in a comment because your question is quite generic, you have not stated the "real goal" or actual use case and the requirements. – ignis Oct 14 '14 at 18:18