Volomike
Volomike

Reputation: 24886

Bash or PHP Cron Script To Clear Out Email

In cPanel on Linux hosting, they let you create email forwarders, but the original emails still reside on the server. Because of spam filtering, however, some of that mail may be kept back and I may be called to debug the email. So, leaving the mail on the mail server for awhile seems a good idea.

Okay, but then once every 4 months, I will want to have a script that empties these email accounts out, deleting the inbox messages.

How do I build a Bash script that I can run on Cron that empties out these mail accounts?

And if not that, then a PHP script?

Upvotes: 2

Views: 391

Answers (1)

dogbane
dogbane

Reputation: 274622

4 months ~ 120 days

You can use find to delete files older than a certain number of days. Place this in your crontab to run on the first day of every month, say at 9am:

00 09 1 * * find /path/to/mail -type f -mtime +120 -print -exec rm {} \; > /var/tmp/mailDelete.log 2>&1

Cron format is:

[min] [hour] [day_of_month] [month] [day_of_week] [command]

Upvotes: 2

Related Questions