Results 1 to 12 of 12

Thread: Cron job for removing old mail

  1. #1
    Join Date
    Dec 2017
    Posts
    6

    Cron job for removing old mail

    Hi their.

    Hope someone can help me out.

    I'm trying to remove/prune mails older then 90 day's.

    I use this line in cron -> rm -f `find /home/rpsmolders/imap/*/*/Maildir/.Sent -mtime +90 | grep -E '/cur/|/new/'` >/dev/null 2>&1
    And it is working great.

    Now their is also a .Sent Items folder (space between)

    I tried the following lines
    rm -f `find /home/rpsmolders/imap/*/*/Maildir/.Sent Items -mtime +90 | grep -E '/cur/|/new/'` >/dev/null 2>&1
    rm -f `find /home/rpsmolders/imap/*/*/Maildir/.Sent\ Items -mtime +90 | grep -E '/cur/|/new/'` >/dev/null 2>&1
    rm -f `find "/home/rpsmolders/imap/*/*/Maildir/.Sent Items" -mtime +90 | grep -E '/cur/|/new/'` >/dev/null 2>&1
    rm -f `find "/home/rpsmolders/imap/*/*/Maildir/.Sent\ Items" -mtime +90 | grep -E '/cur/|/new/'` >/dev/null 2>&1

    But none of them are working.

    Hoop anyone can help me out.

    tnx in advance

    Jeroen

  2. #2
    Join Date
    Jun 2013
    Location
    Dutch Mountains
    Posts
    272
    I would personally definitely not want such a thing to happen, but can't you use wildcard after .sent, like .Sent* ?
    So any Sent folder would its content deleted after 90 days.

  3. #3
    Join Date
    Dec 2017
    Posts
    6
    Hi BBM

    tnx for your reply

    tried rm -f `find /home/rpsmolders/imap/*/*/Maildir/.Sent* -mtime +90 | grep -E '/cur/|/new/' >/dev/null 2>&1

    but this is also not working

    Can you please explain why you wouldn't do this. I no 90 day is not much but it's for testing purpose. when it is working i will set it to 1 year.
    This frees up a lot of disk space for my vps.

  4. #4
    Join Date
    Apr 2005
    Location
    GMT +7.00
    Posts
    12,010
    Hello,

    My guess is that you have too many files for removal, hence it fails.

    What error do you get if you run the commands without ">/dev/null 2>&1" ?

  5. #5
    Join Date
    Dec 2017
    Posts
    6
    Quote Originally Posted by zEitEr View Post
    Hello,

    My guess is that you have too many files for removal, hence it fails.

    What error do you get if you run the commands without ">/dev/null 2>&1" ?

    When i try

    rm -f `find /home/rpsmolders/imap/*/*/Maildir/.Sent* -mtime +90 | grep -E '/cur/|/new/'`

    I get

    rm: cannot remove `/home/rpsmolders/imap/rotsplantensmolders.nl/info/Maildir/.Sent': Is a directory
    rm: cannot remove `/home/rpsmolders/imap/rotsplantensmolders.nl/info/Maildir/.Sent': Is a directory
    rm: cannot remove `/home/rpsmolders/imap/rotsplantensmolders.nl/info/Maildir/.Sent': Is a directory
    rm: cannot remove `/home/rpsmolders/imap/rotsplantensmolders.nl/info/Maildir/.Sent': Is a directory
    rm: cannot remove `/home/rpsmolders/imap/rotsplantensmolders.nl/info/Maildir/.Sent': Is a directory
    rm: cannot remove `/home/rpsmolders/imap/rotsplantensmolders.nl/info/Maildir/.Sent': Is a directory
    rm: cannot remove `/home/rpsmolders/imap/rotsplantensmolders.nl/info/Maildir/.Sent': Is a directory
    rm: cannot remove `/home/rpsmolders/imap/rotsplantensmolders.nl/info/Maildir/.Sent': Is a directory
    rm: cannot remove `/home/rpsmolders/imap/rotsplantensmolders.nl/info/Maildir/.Sent': Is a directory
    rm: cannot remove `/home/rpsmolders/imap/rotsplantensmolders.nl/info/Maildir/.Sent': Is a directory
    rm: cannot remove `/home/rpsmolders/imap/rotsplantensmolders.nl/info/Maildir/.Sent': Is a directory
    rm: cannot remove `/home/rpsmolders/imap/rotsplantensmolders.nl/info/Maildir/.Sent': Is a directory
    rm: cannot remove `/home/rpsmolders/imap/rotsplantensmolders.nl/info/Maildir/.Sent': Is a directory
    rm: cannot remove `/home/rpsmolders/imap/rotsplantensmolders.nl/info/Maildir/.Sent': Is a directory
    rm: cannot remove `/home/rpsmolders/imap/rotsplantensmolders.nl/info/Maildir/.Sent': Is a directory
    rm: cannot remove `/home/rpsmolders/imap/rotsplantensmolders.nl/info/Maildir/.Sent': Is a directory
    rm: cannot remove `/home/rpsmolders/imap/rotsplantensmolders.nl/info/Maildir/.Sent': Is a directory
    rm: cannot remove `/home/rpsmolders/imap/rotsplantensmolders.nl/info/Maildir/.Sent': Is a directory
    rm: cannot remove `/home/rpsmolders/imap/rotsplantensmolders.nl/info/Maildir/.Sent': Is a directory
    rm: cannot remove `/home/rpsmolders/imap/rotsplantensmolders.nl/info/Maildir/.Sent': Is a directory


    When i use

    rm -f `find /home/rpsmolders/imap/*/*/Maildir/".Sent\ Items" -mtime +90 | grep -E '/cur/|/new/'`

    I got this

    find: `/home/rpsmolders/imap/*/*/Maildir/.Sent\\ Items': No such file or directory

  6. #6
    Join Date
    Apr 2005
    Location
    GMT +7.00
    Posts
    12,010
    Modify your find command to search only files then.

    Check man find for a help.

  7. #7
    Join Date
    Dec 2017
    Posts
    6
    Quote Originally Posted by zEitEr View Post
    Modify your find command to search only files then.

    Check man find for a help.
    Sorry total noob here. really don't understand what i need to place now.

  8. #8
    Join Date
    Apr 2005
    Location
    GMT +7.00
    Posts
    12,010
    That's OK. Don't worry. We are all noobs here in different aspects of live. The best time to start learning then.

    Carefully read man find and see examples.

    If you don't want to learn, then please search Internet for ready examples or someone who will do it for you.

  9. #9
    Join Date
    Dec 2017
    Posts
    6
    Quote Originally Posted by zEitEr View Post
    That's OK. Don't worry. We are all noobs here in different aspects of live. The best time to start learning then.

    Carefully read man find and see examples.

    If you don't want to learn, then please search Internet for ready examples or someone who will do it for you.

    When is use this line find /home/jworks/imap/*/*/Maildir -name '*Sent*'

    i get the right folders

    /home/jworks/imap/j-works.eu/ban/Maildir/.Sent
    /home/jworks/imap/j-works.eu/info/Maildir/.INBOX.Sent
    /home/jworks/imap/j-works.eu/info/Maildir/.Sent
    /home/jworks/imap/j-works.eu/test/Maildir/.Sent
    /home/jworks/imap/j-works.eu/zaphier/Maildir/.Sent


    but how to combine this with say for example -type f -mtime +90

    so that the files in that folders will show for deletion

  10. #10
    Join Date
    Jun 2016
    Location
    Tucuman - Argentina
    Posts
    45
    There is such option in Admin Configuration. You just set how many days you want of emails and olders are deleted.
    ___________
    TRIX.Hosting

  11. #11
    Join Date
    Dec 2017
    Posts
    6
    Quote Originally Posted by trix.hosting View Post
    There is such option in Admin Configuration. You just set how many days you want of emails and olders are deleted.

    I know but not for the send items. Only for inbox and deleted boxes

  12. #12
    Join Date
    Apr 2005
    Location
    GMT +7.00
    Posts
    12,010
    Code:
    find /home/*/imap/*/*/Maildir/*.Sent /home/*/imap/*/*/Maildir/.Sent <add-your-options>

Posting Permissions

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