Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

/tmp directory clean up 5

Status
Not open for further replies.

zum

Technical User
Mar 31, 2003
148
US
My /tmp directory seems to get cleaned up from time to time, which is a problem because I have some directories I need in there.

How do I stop my /tmp directory from getting cleaned up?

I'm running RedHat 4.

Thanks!
 
Unless you're talking about a product over 10 years old, you are not running "RedHat 4".

The /tmp folder should NEVER be a place where stuff you "need" is kept. Files like Apache session files, .pid files, .lock files or other goodies should be written into application-specific folders outside of the /tmp folder.

It's likely that somewhere in your cron.d, cron.daily, crontab is a program/script that's cleaning up your /tmp folder. IMHO, rightfully so and it should not be tampered with.

Sorry to be kind of a downer, trying to advocate safe computing and all....

Good luck.
D.

D.E.R. Management - IT Project Management Consulting
 
Mostly wrong. Many times an app will choose a known writable directory to create unix sockets, fifos and implement permanent state. If you clean without knowledge of an app you are at risk. This is not unusual, but as thedaver states: is pretty undesirable. Just understanding the app is mostly good enough.
 
In many *nix, /tmp is cleared down when the box is rebooted.

I want to be good, is that not enough?
 
None of the chasing posts is pertinent but I notice my use of the word permanent is misleading. If you delete contents of /tmp in ceretain runlevels without care on an online and operational machine you may cause major problems.
 
The Daver, I think he's talking about RHEL 4... Which is a bit out dated too, but RH still supports it.

/tmp is indeed often cleaned on reboot, sometimes on newer machines with lots of memory /tmp can even be a ramdisk. The idea is that it is "Temporary" and not persistant storage, so don't save there. If an app is dumping stuff into temp: then change apps, look at the settings to see if you can change your output location, or write a cron job to copy it to a better location on regular basis.

[plug=shameless]
[/plug]
 
I'm so pleased my 'chasing post' seems to have become 'pertinent' again!

I want to be good, is that not enough?
 
I was adding that RH4 was probably RHEL 4, and a few work arrounds to the problem.

- Change apps
- Check settings to see if it can save elsewhere
- Cron job

I wasn't simply leaving another post that says "Tmp is temporary" but also offering solutions.

[plug=shameless]
[/plug]
 
Thanks for all the responses.

Here is the kernel version I'm running. 2.6.9-55.0.6.ELsmp

Anyway, I have a 3rd party application software running on the server. This software creates a directory inside the /tmp directory to store it's own temporary files. The problem is that when the /tmp directory gets cleaned out it wipes out the directory that the software created. Without that directory in the /tmp directory the application will not run.

I may just create a cron job process that check that directory is in /tmp and if is not it recreates it.

Thanks.

 
Thank you for the star, Zum, and apologies to anyone who may have got the wrong impression in my earlier post. One wishes there was a 'tongue-in-cheek' emotican!

I want to be good, is that not enough?
 
zum, you can try a couple of things...

first, can the application be configured to use another folder to store it's "stuff"? That's the ideal, and I'm sure it occurred to you.

The second - highly unusual - approach would be to make the application's folder in /tmp to be "immutable". I say unusual because while it's not unusual to make things immutable in the filesystem, normally we do not do so in /tmp

If you are concerned with /tmp/path/to/app/folder being removed/cleaned away, you can do
chattr +i /tmp/path/to/app/folder

This means the folder cannot be deleted without first removing the immutable attribute.

If another Unix admin sees that attribute, they will likely remove it from stuff in /tmp... /tmp is often a breeding ground for unux/linix system compromise code.

Hope that helps....






D.E.R. Management - IT Project Management Consulting
 
One simple solution that i use sometimes is that in the startup script for your program do:

mkdir -f /tmp/directory
chown .... # if needed
chmod .... # if needed
.
.
"Normal startup"


Or put the commands in the machines startup scripts (rc files)
 
zum,

The culprit most likely is "tmpwatch" which as the man pages says:

man tmpwatch said:
removes files which haven't been accessed for a period of time

It is usually installed as /etc/cron.daily/tmpwatch.

You could edit tmpwatch to add a '-x ' for your application's directory (which will cause it to "Skip absolute path; if path is a directory, all files contained in it are skipped too.")

--
ZaSter
 
I think tmpwatch runs with root permission, so I don't know if
Code:
mkdir -f /tmp/directory
chown .... # if needed
chmod .... # if needed
...would work or not, but depending on the contents and how it's used by the program, you could try to use the sticky bit.

Modifying the cron rules for tmpwatch seems most sensible.

Another option is to create a directory under /var and place a symbolic link to it in tmp. If the link gets removed, then simply relink.

[plug=shameless]
[/plug]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top