SOLVED Excluding addresses from auto-delete

cPanel & WHM Version
90.0 (build 17)

HenrichConsulting

Registered
Nov 24, 2020
3
0
1
Brisbane, Australia
cPanel Access Level
Website Owner
Hi all,

I have a very basic cron job set up to delete emails older than ~ 2 months. This was fine until we on-boarded a small group (~5 users) who need to be excluded from this.
Is this possible to do?

The current command is:

find -P ~/mail/domain/*/cur -type f -mtime +62 -exec rm {} \;
 

cPRex

Jurassic Moderator
Staff member
Oct 19, 2014
14,237
2,217
363
cPanel Access Level
Root Administrator
Hey there! Since your command is just using Bash, could you add in a "grep -v" section to exclude the users that don't want to have the mail removed? This may change the way you pipe it to exec, but that might be the easiest option.
 

HenrichConsulting

Registered
Nov 24, 2020
3
0
1
Brisbane, Australia
cPanel Access Level
Website Owner
Hey there! Since your command is just using Bash, could you add in a "grep -v" section to exclude the users that don't want to have the mail removed? This may change the way you pipe it to exec, but that might be the easiest option.
Hi, thanks for the suggestion! I'm still quite new to cron jobs, would you be able to provide a rough example of what it would look like?
 

cPRex

Jurassic Moderator
Staff member
Oct 19, 2014
14,237
2,217
363
cPanel Access Level
Root Administrator
It might be helpful to not think of it as a cron job at all, but just a Bash script that happens to be running inside cron. Once you get Bash to do what you want, you can place it in the cron.

For example, this would get you the details you're looking for, excluding the example email address "[email protected]"

Code:
find -P ~/mail/domain/*/cur -type f -mtime +62 | grep -v "[email protected]"
Since you're adding a "grep" function to your "find" output, you wouldn't be able to use the "-exec" flag, so you'd need to do something like this:

Code:
find -P ~/mail/domain/*/cur -type f -mtime +62 | grep -v "[email protected]" | xargs rm
I always recommend running the command without the "rm" portion first, just so you can confirm what items will be removed.
 
  • Like
Reactions: HenrichConsulting