Results 1 to 6 of 6

Thread: Clean up by date

  1. #1
    Join Date
    Apr 2009
    Beans
    Hidden!
    Distro
    Ubuntu

    Clean up by date

    Hi,

    I have some script running. It places folders with files in /var/tmp
    The problem is that the script doesn't clean up properly and I can't predict the names of the folders.

    What I'm looking for is a simple bash script I can use to clean up that folder by using a cron-job. Let's say delete everything inside folders which are 5 days or older.
    I know that can be a problem since rmdir is for folders and rm for files, but I've installed secure-delete to solve that, because it's capable of removing folders with files in them.
    So I need something that puts the right folder names into this command:

    Code:
    srm -drzvll /var/tmp/[folder name]
    Used version: mythbuntu 9.04 (9.10 didn't work, didn't try 10.04 yet).

  2. #2
    Join Date
    Jun 2008
    Location
    Lancashire, UK
    Beans
    17
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Clean up by date

    Hi,

    For removing folders with files in, use 'rm -R [folder name]', and to run a command to get the file name, use something like this:
    Code:
    rm -R /var/tmp/`other command`
    Note the backticks, ie ` not '. This runs 'other command', and copies the output into the outer command (rm -R /var/tmp/...).

  3. #3
    Join Date
    Apr 2009
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: Clean up by date

    Thanks, but I don't know the folder names.
    Actually, the deleting part was kind of solved, I only need the correct input to select the folders that can be deleted.

  4. #4
    Join Date
    Apr 2009
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: Clean up by date

    bump

  5. #5
    Join Date
    Mar 2009
    Beans
    927
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Clean up by date

    Try somethign along the lines of this, but be careful with it:
    Code:
    find /var/tmp/ -mtime +5 -exec rm -R {} \;

  6. #6
    Join Date
    Apr 2009
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: Clean up by date

    That seems to do the trick.
    I had to test it with -mtime +0 since I had manually deleted all the files a few days ago (0 free space left on the drive) and -mtime +5 didn't do anything.

    Before I put it in a daily script, I ran this line from the prompt:
    Code:
    find /var/tmp/ -mtime +0 -exec rm -R -i {} \;
    It only processed the folder created before yesterday, so +5 (and without the -i) should be more or less a secure way to tell that the files can really be deleted since the conversion script which create the files/folders takes at most 24 hours to complete the conversion.

    I'll mark this thread solved.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •