LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   what to do with files in /tmp (https://www.linuxquestions.org/questions/linux-general-1/what-to-do-with-files-in-tmp-480380/)

Valkyrie_of_valhalla 09-13-2006 04:01 AM

Thanks again everyone.
I think I got it, but I stil have one last question.
Here's what I have done, it can also act as a small howto for others who have this problem:

- Made a shell script called cleartmp.sh :
Quote:

#!/bin/sh
echo "clearing /tmp folder"
find /tmp -atime +3 -type f -exec rm -rf {} \; >& /dev/null
- Moved it to /etc/init.d

- Created a symbolic link in /etc/init.d/rc5.d:
Quote:

ln -s ../cleartmp.sh K22cleartmp
Is that it? How do I check if it does what it should do? I currently have no older files in /tmp, so I can't check if it does that, I looked in dmesg to see if it printed the echo during boot, but it's not there. Or does it execute those after login? I guess not, as suse firewall is also a script there, and it is mentioned in dmesg.

Jongi 09-13-2006 06:54 AM

jlliagre why the never do that comment?

jlliagre 09-13-2006 03:44 PM

Quote:

Originally Posted by Jongi
jlliagre why the never do that comment?

There are three issues in this cron job:
Code:

*/120  *      *      *      *      root    cd /tmp;rm *
1) "*/120 * * * *" could be replaced by "* */2 * * *", that's a minor one, cosmetic only.

2) "cd /tmp" return value is not checked, if for some (unlikely and odd) reason, /tmp doesn't exists at the moment the command is run, the rm will remove everything in the user's home directory (unless the shell quit after the failed cd, not sure if bash does that).

3) the rm command doesn't check if the files it is going to remove are in use, and even if it would, that wouldn't be enough as even usused files can be expected to stay for an ongoing process that will open it later. This rm command would only be safe in a quiet system, with all services and applications stopped, ideally in single user mode.


All times are GMT -5. The time now is 05:59 AM.