
12-15-2008, 07:10 AM
|
|
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
|

12-15-2008, 08:20 AM
|
|
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.
|

12-15-2008, 08:28 AM
|
|
Community Liaison
|
|
Join Date: Mar 2003
Posts: 8,056
|
|
|

12-15-2008, 08:35 AM
|
|
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
|

12-15-2008, 08:42 AM
|
|
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
|

12-15-2008, 09:06 AM
|
|
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
|

12-15-2008, 09:10 AM
|
|
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.
|

12-15-2008, 09:16 AM
|
|
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
|

12-15-2008, 09:18 AM
|
|
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)
|

12-15-2008, 12:11 PM
|
|
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.
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
| 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
HTML code is Off
|
|
|
|
|
|
| Login: |
|
|
| Advertisement: |
|
|
| Web Hosting News: |
|
|
|