Einen Überblick über das Administrationstool KeyHelp der Keyweb AG und dessen Download gibt es auf https://www.keyhelp.de

Dieses Forum soll es interessierten Benutzern ermöglichen, sich über KeyHelp auszutauschen und Hilfe bei Problemen zu finden.

Cronjob to delete all emails older than one month from server.

Gerneral discussion and questions about KeyHelp
Antworten
luxusmind
Beiträge: 3
Registriert: Fr 14. Jun 2019, 17:34

Cronjob to delete all emails older than one month from server.

Beitrag von luxusmind » Do 20. Jun 2019, 23:58

Hello,

First of all Happy holidays to all of you.
I am trying to setup a Cron Job that would delete emails older than one month, but until now i was unsuccessful.

I was using this tutorial while i had my websites hosted on cPanel. And would like to know if that's okay also with KeyHelp or should i do it in another way.

I have posted it instead of pointing to the link.

[root@EcLinux]# touch mailcleaner.sh
Edit the file using your favorite file editor

[root@EcLinux]# vim mailcleaner.sh

find /home/username/mail/yourdomain.com/*/cur -type f -mtime +30 -exec rm -f {} \;
~
:wq
Then change that file to an executable one. (ie file permission to 755)

[root@EcLinux]# chmod 755 /root/mailcleaner.sh
Step 2 : Creating CRON job
Next step is to set the cronjob under root (for setting a cronjob refer this link). Here I’m setting the cron job to run every 1 day of the month.


[root@EcLinux]# crontab -e
0 0 1 * * /root/mailcleaner.sh > /dev/null 2>&1
:wq
[root@EcLinux]# crontab -l : To list all cronjobs.
In this case the file mailcleaner.sh will execute first day of every month and remove all emails older than 30days.

Credits for the tutorial goes to: Crybit
Mit freundlichen Grüßen
Ibrahim
Benutzeravatar
Alexander
Keyweb AG
Beiträge: 999
Registriert: Mi 20. Jan 2016, 02:23

Re: Cronjob to delete all emails older than one month from server.

Beitrag von Alexander » Fr 21. Jun 2019, 08:02

Hello,

With KeyHelp, mails are stored at /var/mail/vhosts/<DOMAIN_PART>/<USERNAME_PART>/cur

So you have to update the path you are using in your mailcleaner.sh
Mit freundlichen Grüßen / Best regards
Alexander Mahr

**************************************************************
Keyweb AG - Die Hosting Marke
Neuwerkstr. 45/46, 99084 Erfurt / Germany
http://www.keyweb.de - http://www.keyhelp.de
**************************************************************
luxusmind
Beiträge: 3
Registriert: Fr 14. Jun 2019, 17:34

Re: Cronjob to delete all emails older than one month from server.

Beitrag von luxusmind » Fr 21. Jun 2019, 15:42

Alexander hat geschrieben:
Fr 21. Jun 2019, 08:02
Hello,

With KeyHelp, mails are stored at /var/mail/vhosts/<DOMAIN_PART>/<USERNAME_PART>/cur

So you have to update the path you are using in your mailcleaner.sh
Thank you a lot for your response.
I'll post it here for future references, there may be other users that would surely search for it in future.

If you want to schedule a Cronjob and delete emails that are older than 30 days all you have to do is add the above command into your crontab.
crontab -e is used to edit cronjobs.
Add it anywhere you want, modify the domain.com with your domain name and the username with your desired email address.
* * * * * find /var/mail/vhosts/domain.com/username/cur -type f -mtime +30 -exec rm -f {} \; >/dev/null 2>&1
Thank you again Alexander.
Mit freundlichen Grüßen
Ibrahim
Antworten

Wer ist online?

Mitglieder in diesem Forum: 0 Mitglieder und 1 Gast