Skip to main content

Excluding addresses from auto-delete

Comments

5 comments

  • cPRex Jurassic Moderator
    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.
    0
  • HenrichConsulting
    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?
    0
  • cPRex Jurassic Moderator
    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 "user@domain.com" find -P ~/mail/domain/*/cur -type f -mtime +62 | grep -v "user@domain.com"
    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: find -P ~/mail/domain/*/cur -type f -mtime +62 | grep -v "user@domain.com" | xargs rm
    I always recommend running the command without the "rm" portion first, just so you can confirm what items will be removed.
    0
  • HenrichConsulting
    That's a helpful tip! It makes a lot more sense with how it's set up. I haven't wiped out everyone's inbox so I think so far, so good. Thanks for your help.
    0
  • cPRex Jurassic Moderator
    You're welcome!
    0

Please sign in to leave a comment.