Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 08-24-2004, 06:03 AM   #1
LQ Newbie
Registered: Jul 2004
Location: Cheshire, UK
Distribution: SuSE 9.0
Posts: 6

Rep: Reputation: 0
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?

Old 08-24-2004, 06:23 AM   #2
Senior Member
Registered: May 2004
Location: Hilliard, Ohio, USA
Distribution: Slackware, Kubuntu
Posts: 1,851

Rep: Reputation: 47
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
Old 08-24-2004, 07:18 AM   #3
LQ Newbie
Registered: Jul 2004
Location: Cheshire, UK
Distribution: SuSE 9.0
Posts: 6

Original Poster
Rep: Reputation: 0
Thanks scuzzman. That works a treat. I was expecting a more complicated solution!


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Writing shell script with mail < logfile humbletech99 Programming 2 11-22-2005 08:20 AM
anonymous folder writing with vsftpd thomas.jt Linux - Networking 3 10-31-2005 08:18 PM
perl script help required to create users and changing the owner to pericular folder sridhar11 Programming 2 10-25-2005 02:16 PM
Writing to a shared home folder confused_bof Linux - Networking 5 05-18-2004 06:50 AM
E-Mail notification to users via SMS (gateway script ok, but notification script?!?) Riku2015 Linux - Networking 10 03-08-2002 10:16 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:25 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration