-   Linux - Newbie (
-   -   writing a script to perform a function on each users mail folder (

jhill 08-24-2004 06:03 AM

writing a script to perform a function on each users mail folder
I have spamassassin working as a spam filter on my fileserver. I want to modify the setup so that spamassassin autolearns which emails are spam and which are not. I understand that it is best to do this using the spamassassin command sa-learn called through a cron task. sa-learn takes a directory as an input so it is possible to say "this folder contains spam" and teach spamassassin.

My problem is how to write the script that calls the sa-learn function for each of the system users.

The users folder structure is something along the lines of

/mail/user1/ (not spam)
/mail/user1/spam (spam)
I want to be able to specify these 2 folders for each user and not worry about modifying the script if I add or remove a user.

Would the best way be to use a for loop along the lines of

for user in allUsers
or base it on the directories for each user, ie if a directory exists perform function?

What commands can I use for these loops?


scuzzman 08-24-2004 06:23 AM

Hmmm... not to good with SpamAssassin as I don't run my own mail server, but if all your users are user1, user2, user3, user[...] then this should do the trick:

# sa-learn /mail/user*/spam

if they're not, and they most likely aren't, try

# sa-learn /mail/*/spam

this should prevent you from having to modify the code. Now: if you have multiple directories in /mail, such as a /mail/etc (?) or something, you'll probably need to specifically exclude those directories if that's possible. Try the man pages for xarg, ls, and commands of that nature. Sorry if I couldn't be more help :)

jhill 08-24-2004 07:18 AM

Thanks scuzzman. That works a treat. I was expecting a more complicated solution!

All times are GMT -5. The time now is 10:40 PM.