Cron Job auto delete emails older than X days in a domain

ahyde

Registered
Oct 21, 2015
3
0
1
Mexico
cPanel Access Level
Website Owner
Hi,
I try to delete all email arrived of 1 month old of a specific domain with a cron job I tried with this commands:

Code:
/usr/bin/archivemail -quiet -delete -days 30 /home/USERNAME/mail/MYDOMAIN.COM/
Code:
find /home/USERNAME/mail/MYDOMAIN.COM/*/cur -type f -mtime +30 -exec rm -f {} \;
Code:
find /home/mail/MYDOMAIN.COM/*/ -quiet -delete -days 30
Code:
find  /home/mail/MYDOMAIN.COM/ -type f -mtime +7 -delete
I have been reading a lot in internet, I read and search in this forum but nothing works for me.
My host it a VPS of Godaddy I don't know if this influences in the command

I read these entries previously and others from internet:
Possible to auto delete old emails after x number of days?
Deleting Mails with Cron ???

Some errors sending to my email are with different commands:
find: missing argument to `-exec'
find: unknown predicate `--delete'
find: `/home/mail/MYDOMAIN.COM/': No such file or directory
 

ahyde

Registered
Oct 21, 2015
3
0
1
Mexico
cPanel Access Level
Website Owner
Thank you for answer :) and yes I replace USERNAME and MYDOMAIN.COM as my user name and the domain what I want delete all emails. I read the entry but did not work, I'm so newbie and I don't understand a lot the commands but I try.

The path what I think is the correc for me is (because I see the path in my host server):
Code:
/home/USERNAME/mail/MYDOMAIN.COM/*/
because when I write the code previously put they don't send me error in the path, but in the command code after send me errors. I have been reading what mean each word in the commands but nothing I don't have idea why don't work :(
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,270
463
Do you see any output if you manually enter the "find" command? Could you send me a private message of the exact command you are using?

Thank you.
 

ahyde

Registered
Oct 21, 2015
3
0
1
Mexico
cPanel Access Level
Website Owner
Sorry but I can't send PM, this error out:
Untitled.png

But anyway this is the code that I wanted send you :)

The path what I think is the correct is:
Code:
find /home/usernamehere/mail/example.com/*
but the commands I don't know why don't works :(

well, this are the commands what I used :

Code:
find /home/mail/example.com/*/ -quiet -delete -days 30
find  /home/mail/example.com/ -type f -mtime +7 -delete
–quiet –delete –months 1 /home/iqmarkethink/mail/example.com/*/
My user is:usernamehere
and my domain: example.com

Really thanks again for you help, I'm soooooooo newbie in this :oops:
 

Attachments

Last edited by a moderator:

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,270
463
Your "find" commands do not appear to use the correct paths. It's searching in "/home/mail" which is not a valid directory location.

Thank you.