Go Back   HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials > Linux Forums > Technical

Do you like HowtoForge? Please consider supporting us by becoming a subscriber.
Reply
 
Thread Tools Display Modes
  #1  
Old 23rd September 2006, 10:45
edge edge is offline
Moderator
 
Join Date: Dec 2005
Location: The Netherlands
Posts: 2,034
Thanks: 265
Thanked 152 Times in 132 Posts
Default the /tmp folder and emptying it?

One of my home made (web) applications running on Debian Sarge is using the /tmp folder to store temporarly files in (they are not needed anymore after beeing processed)

Do I need to create a cron job to empty the /tmp directory, or is this beeing taken care of by itself (if so, I still see some files in it from several days ago!)?
Reply With Quote
Sponsored Links
  #2  
Old 23rd September 2006, 11:16
domino domino is offline
Senior Member
 
Join Date: Aug 2005
Posts: 364
Thanks: 0
Thanked 9 Times in 8 Posts
Default

I edited the sysklogd to clean the /tmp dir on every reboot. I added the following it. It has to be at a specific line and I have to refer to my box when I get home.
Code:
rm -fr /tmp/* /tmp/.??*
I don't think it's a wise idea to clean the directory during production use.
Reply With Quote
  #3  
Old 23rd September 2006, 15:20
edge edge is offline
Moderator
 
Join Date: Dec 2005
Location: The Netherlands
Posts: 2,034
Thanks: 265
Thanked 152 Times in 132 Posts
Default

Hi domino,

Hmm clean the /tmp dir on every reboot...

Not sure if this is an option for me.. My servers do normaly not do a reboot often! (one of the servers is up over 100 days now)

I guess I need to change some code in my application, and let it use an other "temp" directory that I can clean every 6hrs or so.
Reply With Quote
  #4  
Old 23rd September 2006, 15:26
domino domino is offline
Senior Member
 
Join Date: Aug 2005
Posts: 364
Thanks: 0
Thanked 9 Times in 8 Posts
Default

Yea, kinda figured that but I first thought it was a home server and not a dedicated box. I think I remember a read a few years back with using a cron to clean a user /tmp directory. But I think it was on a RH 9 box. I'll post it when I find it. Sorry for the misunderstanding.
Reply With Quote
  #5  
Old 24th September 2006, 14:09
falko falko is offline
Super Moderator
 
Join Date: Apr 2005
Location: Lüneburg, Germany
Posts: 41,701
Thanks: 1,900
Thanked 2,741 Times in 2,575 Posts
Default

Quote:
Originally Posted by edge
One of my home made (web) applications running on Debian Sarge is using the /tmp folder to store temporarly files in (they are not needed anymore after beeing processed)

Do I need to create a cron job to empty the /tmp directory, or is this beeing taken care of by itself (if so, I still see some files in it from several days ago!)?
To go sure you can create a cron job. Create a shell script like this one:

Code:
#!/bin/sh

for file in "$( /usr/bin/find /tmp -type f -mtime +2 )"
do
  rm -f $file
done

exit 0
make it executable, and put it in a cron job. It deletes all files in /tmp that are older than two days.
__________________
Falko
--
Download the ISPConfig 3 Manual! | Check out the ISPConfig 3 Billing Module!

FB: http://www.facebook.com/howtoforge

nginx-Webhosting: Timme Hosting | Follow me on:
Reply With Quote
  #6  
Old 24th September 2006, 14:25
edge edge is offline
Moderator
 
Join Date: Dec 2005
Location: The Netherlands
Posts: 2,034
Thanks: 265
Thanked 152 Times in 132 Posts
Default

Thanks once again falko!

Script is up and running :-)
Reply With Quote
  #7  
Old 29th November 2006, 20:07
sjau sjau is offline
Local Meanie
 
Join Date: Apr 2006
Location: Switzerland
Posts: 1,146
Thanks: 4
Thanked 55 Times in 51 Posts
Default

Why doesn't this work here:

Quote:
#!/bin/sh

for file in "$( /usr/bin/find /backup/ -type d -mtime +3 )"
do
# rm -Rf $file
echo $file
done

exit 0
I try to remove all files in the backup folder that are older than xx days...
Instead of running just the rm command I first wanted to echo it to see it works fine... however nothing is being returned...
Reply With Quote
  #8  
Old 30th November 2006, 00:48
edge edge is offline
Moderator
 
Join Date: Dec 2005
Location: The Netherlands
Posts: 2,034
Thanks: 265
Thanked 152 Times in 132 Posts
Default

I think you will need to set the var $file 1st to echo it.
Now it showing $file, but it's empty!

maybe something like this

Code:
#!/bin/sh

for file in "$( /usr/bin/find /backup/ -type d -mtime +3 )"
do
showIt=$file
# rm -Rf $file
echo $showIt
done

exit 0

Last edited by edge; 30th November 2006 at 00:57.
Reply With Quote
  #9  
Old 30th November 2006, 16:04
falko falko is offline
Super Moderator
 
Join Date: Apr 2005
Location: Lüneburg, Germany
Posts: 41,701
Thanks: 1,900
Thanked 2,741 Times in 2,575 Posts
Default

You can also try to use the full path to echo (you can find out by running
Code:
which echo
).
__________________
Falko
--
Download the ISPConfig 3 Manual! | Check out the ISPConfig 3 Billing Module!

FB: http://www.facebook.com/howtoforge

nginx-Webhosting: Timme Hosting | Follow me on:
Reply With Quote
  #10  
Old 1st December 2006, 11:38
sjau sjau is offline
Local Meanie
 
Join Date: Apr 2006
Location: Switzerland
Posts: 1,146
Thanks: 4
Thanked 55 Times in 51 Posts
 
Default

Hmmm, does not work
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 12:17.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.