Last active
April 22, 2022 12:13
-
-
Save beatwiz/58dac7e2b32425ce81417d4a365f2cc9 to your computer and use it in GitHub Desktop.
[bash] cPanel / WHM Cron bash script to delete all accounts > domains > users, trash / spam / junk emails with more than 30 days
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# All users from all domains from all accounts in /home | |
MAILDIRS=$(find /home/*/mail/ -type d) | |
# Only .Trash .Junk .Spam folders | |
INBOXFOLDERS=(.Trash .Junk .spam) | |
for basedir in $MAILDIRS; do | |
for ((i = 0; i < ${#INBOXFOLDERS[*]}; i++)); do | |
# Only cur and new folders | |
for dir in cur new; do | |
# Only if the full path to the folder exists | |
[ -e "$basedir/${INBOXFOLDERS[$i]}/$dir" ] && ( | |
# Delete files with more than 30 days | |
find "$basedir/${INBOXFOLDERS[$i]}/$dir/" -type f -mtime +30 -delete | |
) | |
done | |
done | |
done | |
# Save as /folder/cleartrash.sh and setup on cron daily: | |
# /folder/cleartrash.sh >/dev/null 2>&1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment