The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How to delete files 24 hours old?

Discussion in 'General Discussion' started by trakwebster, Feb 12, 2004.

  1. trakwebster

    trakwebster Well-Known Member

    Joined:
    Jan 29, 2003
    Messages:
    145
    Likes Received:
    0
    Trophy Points:
    16
    I wonder if anyone here could tell me how to write a bash script which would wipe specified files in a specified directory, but only if those files were so many hours old.

    For example (in pseudo-code):

    Foreach file in thisdirectory,
    if filedate > 24hours
    then rm thisfile

    Anybody know how to do it?
     
  2. chirpy

    chirpy Well-Known Member

    Joined:
    Jun 15, 2002
    Messages:
    13,475
    Likes Received:
    20
    Trophy Points:
    38
    Location:
    Go on, have a guess
    You could use tmpwatch

    man tmpwatch

    You can use it on any specified directory.
     
  3. trakwebster

    trakwebster Well-Known Member

    Joined:
    Jan 29, 2003
    Messages:
    145
    Likes Received:
    0
    Trophy Points:
    16
    Wonderful!

    Wow, chirpy!

    That's great! No bash programming required!

    Thank you so very much!

    PS: On another subject, your WebUMake product looks pretty good. Did you design it? Do you use this product in your WayToTheWeb hosting service? It looks pretty slick, so I'd be interested to know these two things.

    Have you spoken with Kosmo at cpanelthemes.com regarding possible co-venture bundling WebUMake with fantastico? Just an idea ...
     
    #3 trakwebster, Feb 12, 2004
    Last edited: Feb 12, 2004
  4. chirpy

    chirpy Well-Known Member

    Joined:
    Jun 15, 2002
    Messages:
    13,475
    Likes Received:
    20
    Trophy Points:
    38
    Location:
    Go on, have a guess
    I wrote most of the products :)

    If we had some freeware I'd be happy to contact Kosmo, but unfortunately most of our products have a license cost involved and probably wouldn't be suitable.

    We don't use our products as part of our hosting plans for our hosting clients, but we do have hosting clients that use our products ;-)
     
  5. nickn

    nickn Well-Known Member
    PartnerNOC

    Joined:
    Jun 15, 2003
    Messages:
    619
    Likes Received:
    1
    Trophy Points:
    18
    You could crontab this:

    Code:
    cd /tmp ; find . ! -name . ! -name lost+found -type dfl -mtime +1 -exec /bin/rm -rf {} ';'
    
    This would delete all files/symlink/directories (other than lost+found) older than 24 hours.

    I'm not completely positive you can combine multiple types, if not you would use :

    Code:
    cd /tmp ; find . -type l -mtime +1 -exec /bin/rm {} ';'
    
    Code:
    cd /tmp ; find . -type f -mtime +1 -exec /bin/rm {} ';'
    
    Code:
    cd /tmp ; find . ! -name . ! -name lost+found -type d -mtime +1 -exec /bin/rm -rf {} ';'
    
    Those three could be crontab'd.
     
  6. trakwebster

    trakwebster Well-Known Member

    Joined:
    Jan 29, 2003
    Messages:
    145
    Likes Received:
    0
    Trophy Points:
    16
    thanks, Nick!

    Very nice!
     
  7. jamesbond

    jamesbond Well-Known Member

    Joined:
    Oct 9, 2002
    Messages:
    738
    Likes Received:
    1
    Trophy Points:
    18
    What would happen if 'cd /tmp' didn't work because the tmp directory was removed somehow (or any other reason) and these cronjobs would run? ;)

    Maybe not very likely, but still I think it's better to make sure that 'rm -rf' only gets executed after you checked that you're actually in the /tmp directory.
     
  8. Roy@ENHOST

    Roy@ENHOST Well-Known Member

    Joined:
    Mar 5, 2002
    Messages:
    495
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    Los Angeles California
    Sorry to get a lil sidetracked here but why don't you offer the your products to your hosting customers? I mean you don't have to pay a single penny as you wrote it and having that extra feature in your webhosting service is definitely going to make it more attractive to potential customer ain't it?
     
  9. chirpy

    chirpy Well-Known Member

    Joined:
    Jun 15, 2002
    Messages:
    13,475
    Likes Received:
    20
    Trophy Points:
    38
    Location:
    Go on, have a guess
    The reason is mostly historical. Our web hosting has traditionally been for small businesses only within the UK and we haven't had any demand from our hosting customer base for our scripting products because of the way they use web hosting. We used to offer our own scripts, but they weren't used.

    We're now upgrading all of our hosting accounts from the old blue pizza box RaQ4's to cPanel accounts and now may be a good time to look into that again.

    ( Apologies for anyone readying this thread who couldn't care less ;) )
     
  10. SuperBaby

    SuperBaby Well-Known Member

    Joined:
    Nov 27, 2003
    Messages:
    331
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    Thailand
    cPanel Access Level:
    Website Owner
    Twitter:
    You can also use this CGI script from www.upoint.info/cgi if you need a web-based interface:

    - Auto Delete II

    Online demo available.
     
  11. hostit1

    hostit1 Well-Known Member

    Joined:
    Jul 24, 2003
    Messages:
    88
    Likes Received:
    0
    Trophy Points:
    0
    I created a cron that does the below that runs hourly
    rm -fR /tmp/sess_* /tmp/php* /tmp/cpanel.TMP*

    This may not be the best way, but it works well.

    There seems to be some concern regarding security issues using the 'tmpwatch' feature. I don't know how reliable the sorurce or the information is, but maybe someone can read the below article and post some feedback.

    http://www.bindview.com/Support/RAZOR/Papers/2002/mkstemp.cfm

    Sincerely,

    Tim Rice
    Host It Now Networks
     
Loading...

Share This Page