(OT) place on linux box to safely create tons of temp junk???
leocharre
created: 2006-04-02 16:17:48

I am generating temp files.. I know that i can use a cron job, to clean up. I was wondering.. is there some place on a linux box where any user can naturally put temp files? does the tmp dir work like that? so i can gerenate temp junk endlessly without worry of clean up ?

Also I don't want to be a buttmunch asking this stuff in the wrong place.. is there a more appropriate (although i already know not better.. ) place where i can ask unix/linux questions that could be suggested? I'm having a hard time finding a good place for this. Thank you ahead for any help. I hope I don't annoy anyone with this.

Re: (OT) place on linux box to safely create tons of temp junk???
created: 2006-04-02 16:28:27
Re: (OT) place on linux box to safely create tons of temp junk???
created: 2006-04-02 19:27:21
Whether or not any directories on the system have old files removed periodically depends on the system's configuration, or if you haven't configured it, its defaults. So the first thing to do is poke around inside your system's documentation and/or cron configuration and see if it's already cleaning anything. If not, set it up to automatically clean /tmp, then write your files there.

File::Temp is a useful way to create tempfiles, but you'll still have to figure out how to get them cleaned up.

Also, it's best if you can clean them up yourself, and only leave them lying around in the rare case that your program crashes. Things like END blocks are useful places for this sort of cleanup.

Re^2: (OT) place on linux box to safely create tons of temp junk???
created: 2006-04-02 23:17:55
Actually, File::Temp will clean up after you if you want it to.
Re^3: (OT) place on linux box to safely create tons of temp junk???
created: 2006-04-03 12:22:14
Yes indeed, I didn't know that! Very handy. Not entirely foolproof, for example if your process crashes perl or is killed with SIGKILL, but probably close enough for most purposes.
Re^2: (OT) place on linux box to safely create tons of temp junk???
created: 2006-04-04 13:05:55
About cleaning them up myself.. I am creating some modules, and i have distribution in mind. I only trust people downloading and configuring so far- installing a module, and setting up a cron, may be too much to expect from some people.
Re^3: (OT) place on linux box to safely create tons of temp junk???
created: 2006-04-04 13:47:45
Then just let them configure where temp files go, defaulting to /tmp, try your best to clean them up when you exit, and document that some systems won't automatically clean that area, and on the rare occasion something goes Very Wrong, the user may need to clean it manually once in awhile, or set up a cronjob to do it automatically. That's really all you can do.
Re: (OT) place on linux box to safely create tons of temp junk???
created: 2006-04-02 19:59:39

Sick Unix Trick #347 ... ghost files.

# Open the file, creating it
open $fh, '+>', 'foo.txt';

# Immediately unlink the file ... it will remain
# until you close the filehandle, then disappear
unlink 'foo.txt';

# Put something in it to test
print $fh "Foo\n";

# Rewind to the start of the temp file
seek $fh, 0, 0;

# Read it back in and see what you have
$in = <$fh>;
print "Read: $in\n";

# You don't even *have* to remember to close it,
# but it is a good habit ...
close $fh;

The intelligent reader will judge for himself. Without examining the facts fully and fairly, there is no way of knowing whether vox populi is really vox dei, or merely vox asinorum. — Cyrus H. Gordon
Re: (OT) place on linux box to safely create tons of temp junk???
created: 2006-04-02 21:21:58

By unix rules, the system normally should not remove anything from /tmp while running. In /tmp any program is supposed to be able to create files, write to them, and assume that files placed there will remain until removed by the owner. A program can not assume that the contents of /tmp will survive a reboot. That makes startup scripts the place for the system to do /tmp cleanup.

Some admins put in place some other policy they dream up, but the unix police will someday get 'em.

Putting /tmp on its own spindle, or at least a large partition, and mounting with the sticky bit set fixes most problems that non-unix policies are meant to solve. Going all BOFH on programs which don't clean up after themselves takes care of the rest.

Of course, users may clean up their own messes any time they like.

After Compline,
Zaxo

Re: (OT) place on linux box to safely create tons of temp junk???
created: 2006-04-02 21:58:48
In re where to ask Unix/Linux qns, try www.linuxquestions.org, I think you'll like it.
Of course there are plenty of Unix/Linux monks here...
Re^2: (OT) place on linux box to safely create tons of temp junk???
created: 2006-04-03 05:18:31
Of course there are plenty of Unix/Linux monks here...
In which case, we prefer you to use the Chatterbox to ask quick questions.

perlmonks.org content © perlmonks.org and bart, chrism01, idsfa, leocharre, perrin, sgifford, Zaxo

prlmnks.org © 2006 edmund von der burg (eccles & toad)

v 0.03