hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Hosting Security and Technology : Cleaning-up the /tmp partition
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

Cleaning-up the /tmp partition

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 02-24-2008, 03:54 AM
Bdzzld Bdzzld is offline
Junior Guru Wannabe
 
Join Date: May 2004
Posts: 83
Question

Cleaning-up the /tmp partition


Hi,

I'm looking for a (new) script which can be run daily (via a cronjob) and deletes every file in the /tmp partition which has not been used in a week.

I'm currently using the following :
Code:
find /tmp -mtime +8 -exec rm {} \;
but that only deletes those files and does not show the files being deleted and not even the amount of files being deleted.

Any ideas how to extend this script or rewrite it? The server runs CENTOS Enterprise 4.6 x86_64.

Thanks.


Last edited by Bdzzld; 02-24-2008 at 03:57 AM.
Reply With Quote


Sponsored Links
  #2  
Old 02-24-2008, 04:30 AM
hermetek hermetek is offline
Web Hosting Guru
 
Join Date: Feb 2008
Location: Longview, Texas
Posts: 272
find /tmp -mtime +8 | xargs rm -fv

...and then you could use a redirect to log it.

__________________
██ HermeTek Network Solutions
██ Network design, security, and implementation
██ BSD & Linux consulting, training, and hosting
██ https://www.hermetek.com | 1.866.235.1288

Reply With Quote
  #3  
Old 02-24-2008, 05:26 AM
david510 david510 is offline
Web Hosting Master
 
Join Date: Oct 2004
Location: Kerala, India
Posts: 4,617
Use below. Make a new directory /var/tmplogs. The script will make a file with current date, fill the file with the files that will be removed and will remove those files from /tmp.

Code:
#!/bin/sh
find /tmp -mtime +8 > /var/tmplogs/log-`date -I`
find /tmp -mtime +8 | xargs rm -fv

__________________
David | www.cliffsupport.com
Affordable Server Management Solutions sales AT cliffsupport DOT com
iWebManager | Access WHM from iPhone and Android

Reply With Quote
Sponsored Links
  #4  
Old 02-24-2008, 06:58 AM
Bdzzld Bdzzld is offline
Junior Guru Wannabe
 
Join Date: May 2004
Posts: 83
Thanks for the suggestions so far...
If you write all file names of the files to be deleted to a logfile first, ain't it easier to use that logfile to remove the files instead of reissueing the 'find' command? Afaik the 'find' command can be heavy on resources...

Reply With Quote
  #5  
Old 02-24-2008, 07:45 AM
david510 david510 is offline
Web Hosting Master
 
Join Date: Oct 2004
Location: Kerala, India
Posts: 4,617
Modify the script as follows.

Code:
#!/bin/sh
find /tmp -mtime +8 > /var/tmplogs/log-`date -I`
for i in  $(cat /var/tmplogs/log-`date -I`) ; do rm -rf $i ; done

__________________
David | www.cliffsupport.com
Affordable Server Management Solutions sales AT cliffsupport DOT com
iWebManager | Access WHM from iPhone and Android

Reply With Quote
  #6  
Old 02-24-2008, 09:45 AM
Bdzzld Bdzzld is offline
Junior Guru Wannabe
 
Join Date: May 2004
Posts: 83
I've now rewritten the script based on your suggestions.
Bash scripts can be quite powerfull

Is there also some way to check if the /var/tmplogs/ path has already been created and if not create it?

Thanks.

Reply With Quote
  #7  
Old 02-24-2008, 01:40 PM
slinek slinek is offline
Newbie
 
Join Date: Oct 2007
Posts: 11
Quote:
Originally Posted by Bdzzld View Post
I've now rewritten the script based on your suggestions.
Bash scripts can be quite powerfull

Is there also some way to check if the /var/tmplogs/ path has already been created and if not create it?

Thanks.
Code:
#!/bin/bash
if [ ! -d "/var/tmplogs" ]; then
mkdir /var/tmplogs
fi

Reply With Quote
  #8  
Old 02-24-2008, 03:08 PM
Tim Greer Tim Greer is offline
<insert something witty>
 
Join Date: Apr 2000
Location: California
Posts: 3,051
First, mtime is the modification time. If you want files that were just not "accessed" for over 8 days, then you'd use -atime instead.

Also, you don't need to run any additional commands, you can just use:

find /tmp -atime +8 -exec rm -vf {} \; > /var/tmplogs/log-`date -I`

This way it will run the rm command in forced, verbose mode and the redirect > will write to the dated log file.

You might want to add some commands to ignore links. Also, make sure the path for the log file exists and is writable and set the cron accordingly.

Reply With Quote
  #9  
Old 02-26-2008, 03:50 AM
Bdzzld Bdzzld is offline
Junior Guru Wannabe
 
Join Date: May 2004
Posts: 83
If files are scanned on a regular basis in the /tmp path for possible abuses - which is what the csf/lfd combo does f.i. - substituting
Code:
-mtime
with
Code:
-atime
as you suggest, will not find any files at all.


Last edited by Bdzzld; 02-26-2008 at 03:59 AM.
Reply With Quote
  #10  
Old 02-26-2008, 01:38 PM
Tim Greer Tim Greer is offline
<insert something witty>
 
Join Date: Apr 2000
Location: California
Posts: 3,051
A file could not be modified for weeks, but be accessed every hour. This is why I recommended a check for access time instead of modification? Anyway, yeah, if the files are actually opened/read by some exploit checker, then the access time will be updated (and not the modification time). I don't think much of those scanners, but I'd have assumed it only checked the file once, within minutes (or hours) of creation time and shouldn't read them again unless the modification time changed.

Anyway, use -mtime if you want or need to, but I'd save processing with:

find /tmp -mtime +8 -exec rm -vf {} \; > /var/tmplogs/log-`date -I`


Last edited by Tim Greer; 02-26-2008 at 01:42 PM.
Reply With Quote
Reply

Related posts from TheWhir.com
Title Type Date Posted
Codero Hosting Launches On-Demand Storage Services Web Hosting News 2013-04-30 14:58:12
Polish Domain Registry NASK Seizes Domains Used in Pervasive Virut Botnet Web Hosting News 2013-01-21 16:56:31
A Look at Virsto Software's Storage Hypervisor Solutions Web Hosting News 2012-02-07 13:46:17
Cloud Firm Amazon Web Services Launches NoSQL Database Service Web Hosting News 2012-01-18 16:00:08
Virsto Software Receives Microsoft Windows Server 2008 R2 Certification Web Hosting News 2011-10-14 19:25:06


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?