Cron job for removing old mail

jeroenenwendy

Verified User
Joined
Dec 1, 2017
Messages
6
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
 

BBM

Verified User
Joined
Jun 8, 2013
Messages
342
Location
Dutch Mountains
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.
 

jeroenenwendy

Verified User
Joined
Dec 1, 2017
Messages
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.
 

zEitEr

Super Moderator
Joined
Apr 11, 2005
Messages
14,243
Location
GMT +7.00
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" ?
 

jeroenenwendy

Verified User
Joined
Dec 1, 2017
Messages
6
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
 

zEitEr

Super Moderator
Joined
Apr 11, 2005
Messages
14,243
Location
GMT +7.00
Modify your find command to search only files then.

Check man find for a help.
 

zEitEr

Super Moderator
Joined
Apr 11, 2005
Messages
14,243
Location
GMT +7.00
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.
 

jeroenenwendy

Verified User
Joined
Dec 1, 2017
Messages
6
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
 

zEitEr

Super Moderator
Joined
Apr 11, 2005
Messages
14,243
Location
GMT +7.00
Code:
find /home/*/imap/*/*/Maildir/*.Sent /home/*/imap/*/*/Maildir/.Sent <add-your-options>
 
Top