将文件移动到相对目录匹配 - 垃圾邮件处理

时间:2015-08-15 09:47:58

标签: bash mv spamassassin

我正在设置一个脚本来学习maildir文件夹中的垃圾邮件“.LearnAsSpam”

了解垃圾邮件后,我想将所有垃圾邮件移至所有用户的“.Junk”文件夹:

即:

  • / home / vmail / domain1 / user1 /Maildir/.LearnAsSpam/cur/* - > /home/vmail/domain1/user1/Maildir/.Junk/cur /

  • / home / vmail / domain1 / user2 /Maildir/.LearnAsSpam/cur/* - > /home/vmail/domain1/user2/Maildir/.Junk/cur /

是否有一种简单的方法可以编写一个bash脚本来正确匹配并移动每个用户的文件?

1 个答案:

答案 0 :(得分:0)

好的,认为这样可行:

find /home/vmail/ -type d -path "*/*/Maildir/.LearnAsSpam/cur" -exec sh -c '(cd {} && mv ./* ../../.Junk/cur)' ';'

万一有人对此感兴趣,垃圾邮件学习和移动垃圾邮件的整个脚本如下所示:

# do a spam check in LearnAsSpam and LearnAsHam folders
# find spam
sa-learn -p ~/.spamassassin/user_prefs --spam /home/vmail/*/*/Maildir/.LearnAsSpam/{cur,new}
# find ham
sa-learn -p ~/.spamassassin/user_prefs --ham /home/vmail/*/*/Maildir/.LearnAsHam/{cur,new}
# move spam
find /home/vmail/ -type d -path "*/*/Maildir/.LearnAsSpam/cur" -exec sh -c '(cd {} && mv ./* ../../.Junk/cur)' ';'
find /home/vmail/ -type d -path "*/*/Maildir/.LearnAsSpam/new" -exec sh -c '(cd {} && mv ./* ../../.Junk/new)' ';'
# move ham
find /home/vmail/ -type d -path "*/*/Maildir/.LearnAsHam/cur" -exec sh -c '(cd {} && mv ./* ../../.Inbox/cur)' ';'
find /home/vmail/ -type d -path "*/*/Maildir/.LearnAsHam/new" -exec sh -c '(cd {} && mv ./* ../../.Inbox/new)' ';' 

这被添加到/etc/cron.daily/spamassassin脚本