hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Hosting Security and Technology : How Do You Create A Cron Job To Clear Your /tmp Folder Automatically?
Reply

Hosting Security and Technology Configuring and optimizing web hosting servers and operating systems, developing administration scripts, building servers, protecting against hackers, and general security (SSL certificates, etc.)
Forum Jump

How Do You Create A Cron Job To Clear Your /tmp Folder Automatically?

Reply Post New Thread In Hosting Security and Technology Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old 12-15-2008, 07:10 AM
SupportRep911 SupportRep911 is offline
Aspiring Evangelist
 
Join Date: Jun 2007
Posts: 415
How Do You Create A Cron Job To Clear Your /tmp Folder Automatically?

Hi,
Can someone please let me know how I can create a cron job that runs every 10minutes or so to clear my /tmp folder on one of my servers?
Reason I ask is, it keeps getting filled up and doesn't delete the fiels in it and stops certain scripts from running.
Also, again, I need step by step instructions, such as:
1) what, where the file is I need to place the cron job in
2) what line of code would I put in that file (what does the cron job line look like for every 10min every day)
3) do I need to restart anything, and if so, what command do I run in shell?
Thanks everyone





__________________
||| HastyHost.com||| Shared, Reseller, and VPS||| Beware, We Do Not Oversell Services

Reply With Quote


Sponsored Links
  #2  
Old 12-15-2008, 08:20 AM
Nizumzen Nizumzen is offline
Junior Guru
 
Join Date: Mar 2006
Posts: 205
Do you have cPanel at all? A simple command would be:
#!/bin/sh
rm -rf /tmp/*
then in cPanel just set the date and time to run the script and point it to where you saved the script (add a .sh extension to it for correctness).
Be warned this will delete absolutely everything in the /tmp directory permanently!
You may need to run this to make the script executable:
chmod +x script_file_name.sh





Last edited by Nizumzen : 12-15-2008 at 07:27 AM.

Reply With Quote
  #3  
Old 12-15-2008, 08:28 AM
net net is offline
Community Liaison
 
Join Date: Mar 2003
Posts: 8,056
Moved > Technical

Reply With Quote
Sponsored Links
  #4  
Old 12-15-2008, 08:35 AM
SupportRep911 SupportRep911 is offline
Aspiring Evangelist
 
Join Date: Jun 2007
Posts: 415
Quote:



Originally Posted by Nizumzen


Do you have cPanel at all? A simple command would be:
#!/bin/sh
rm -rf /tmp/*
then in cPanel just set the date and time to run the script and point it to where you saved the script (add a .sh extension to it for correctness).
Be warned this will delete absolutely everything in the /tmp directory permanently!
You may need to run this to make the script executable:
chmod +x script_file_name.sh


Wait, is "rm -rf/tmp/ the script, or command?
Where do I get the script from if that is not, or how to I make it, and what do I put inside it?
Thanks for your help





__________________
||| HastyHost.com||| Shared, Reseller, and VPS||| Beware, We Do Not Oversell Services

Reply With Quote
  #5  
Old 12-15-2008, 08:42 AM
040Hosting 040Hosting is offline
Community Liaison
 
Join Date: May 2006
Location: EU & USA
Posts: 3,626
Be extremely careful, a better approach would be to look which programs are filling up your /tmp/ and see if you can fix this issue.
If you really need to remove file automatically make sure you do not remove all files in the /tmp/ directory; i.e. some systems use this for PHP sessions; these would then automatically be removed, and nobody can stay logged in longer as 10 minutes. (or in the worst case even a few seconds).
The approach of doing the rm -rf /tmp/ is a *BAD* idea. it would remove ALL files and sub directories in your /tmp/ directory, one mistake in typing it; and you clean your web server up a bit to much...
If you really need to remove files frequently make sure you know which files (is there any logic to it?) and why they are there; in the worst case you could remove these files automatically but it is better to use another syntax which only removes the affected files.
What information do you have about the files which are stored there so frequently which do not belong there ?
In my book all files in /tmp/ should have a reason; therefor look why they are created there in the first place.





__________________ Being good in business is the most fascinating kind of art - Andy Warhol
» 040 Hosting (Registered company #17093425 KVK Eindhoven, The Netherlands)






Last edited by 040Hosting : 12-15-2008 at 07:45 AM.
Reason: typos

Reply With Quote
  #6  
Old 12-15-2008, 09:06 AM
SupportRep911 SupportRep911 is offline
Aspiring Evangelist
 
Join Date: Jun 2007
Posts: 415
Really, it's a bunch of these: sess_035e6f65f4f0cea8fefb174f30833259
which are produced by a script called iPanel.
When my tmp gets full, iPanel wont work and sends out a sql error saying that it cannot execute a .php file.
I asked iPanel about it and they said that it had something to do with our php settings on the server, but I'm not sure what to do to prevent all the, sess_035e6f65f4f0cea8fefb174f30833259 , from showing up.
Any help is appreciated,
Thanks





__________________
||| HastyHost.com||| Shared, Reseller, and VPS||| Beware, We Do Not Oversell Services

Reply With Quote
  #7  
Old 12-15-2008, 09:10 AM
ub3r ub3r is offline
Disabled
 
Join Date: Dec 2002
Location: chica go go
Posts: 11,858
correct command:
find /tmp -iname 'sess_*' -exec rm -rf {} \;
that's going to screw up your users' php sessions if the session files are removed while the sessions are active.

Reply With Quote
  #8  
Old 12-15-2008, 09:16 AM
vx|brian vx|brian is offline
Aspiring Evangelist
 
Join Date: Jul 2006
Location: Montreal, Canada
Posts: 369
Here is an article that has a very nice clean up script that takes care of the good stuff and leaves active sessions and cleans them up if they're older than 7 days: http://momotonic.com/2008/11/28/tmp-...ying-with-php/






__________________█ vexxhost web hosting: Innovative high performance web hosting solutions.
█ Operating at our own private datacenter space

Reply With Quote
  #9  
Old 12-15-2008, 09:18 AM
040Hosting 040Hosting is offline
Community Liaison
 
Join Date: May 2006
Location: EU & USA
Posts: 3,626
Quote:



Originally Posted by SupportRep911


Really, it's a bunch of these: sess_035e6f65f4f0cea8fefb174f30833259
which are produced by a script called iPanel.
When my tmp gets full, iPanel wont work and sends out a sql error saying that it cannot execute a .php file.
I asked iPanel about it and they said that it had something to do with our php settings on the server, but I'm not sure what to do to prevent all the, sess_035e6f65f4f0cea8fefb174f30833259 , from showing up.
Any help is appreciated,
Thanks


You should either read up on PHP Sessions or contact a server management company to solve it; i would strongly advise not to just remove these files as it will only bring extra load to your server and not solve the issue.
Sess_ files are session files; if you want to do a cheap work around like you suggested in your earlier post you could issue the following command in cron;find /tmp/sess_* -mtime +5 -type f -exec rm -rf {} \;
This command will do a search in /tmp for all files starting with "sess_" that were last modified 5 or more days ago and executes a recursive forced (-rf) remove (rm).
The "{}" is the place holder for exec to use where it will put the name of the file, and the "\;" tells exec that's the end of the statement.
I would suggest to test this first ; you can replace the "rm -rf" with "echo" to see if the output gives you the files you want to remove.





__________________ Being good in business is the most fascinating kind of art - Andy Warhol
» 040 Hosting (Registered company #17093425 KVK Eindhoven, The Netherlands)

Reply With Quote
  #10  
Old 12-15-2008, 12:11 PM
zacharooni zacharooni is offline
Community Guide
 
Join Date: Apr 2005
Posts: 1,214
You don't want to remove /tmp/*, as this will mess up a cPanel server, and you will have to recreate the MySQL symlink.
I would advise creating a session directory under your user account, and creating a PHP.INI that says:
session.save_path = /home/USERNAME/session/
Then make this directory writable (0755), or higher permissions if needed, since it's outside of docroot shouldn't matter that much. This will store php session files inside of /home/USERNAME/session/ , from which it will be much safer to remove cookies without having to worry about removing anything important.

Reply With Quote
Reply

Related posts from TheWhir.com
Title Type Date Posted
Jelastic Launches Version 1.9.1 of Java and PHP Hosting Platform Web Hosting News 2013-05-21 09:39:09
Cloud Storage Firm Mozy Launches Stash File Sync Tool in Beta Web Hosting News 2012-01-26 18:00:33
Pancake.io, DropPages Let Users Host Web Site Files on DropBox Blog 2011-12-08 17:03:11
Telecommunications Firm AT&T Launches Mobile Website Builder Web Hosting News 2011-09-15 20:40:54
Open Source Developer Joomla Releases 1.7 CMS with Enhanced Security Tools Web Hosting News 2011-07-19 18:51:20


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Postbit Selector

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 Off
HTML code is Off

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
Advertisement:
Web Hosting News:



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?