[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [vps-mail] Bayes --force-expire problem



On Sat, May 08, 2004 at 10:38:55PM -0400, Jim Smith wrote:
> Scott,
> I tried your script but without success. I understand to run su to change
> the privileges. However, when it runs "sa-learn --force-expire" it still
> tries to force-expire the /root/.spamassassin/ files instead of the
> /home/$USER/.spamassassin/ files. It errors out with a "Permission denied"
> message. Even when I cd to the correct directory, it still tries to expire
> the root SA files. Any suggestions?

Hm. sounds like sa-learn uses the $HOME environment variable instead
of doing a getpwuid() call. Bad sa-learn. Here's something a little
more robust in Perl that you can run as root:

perl -e 'for $user (@ARGV) { $>=getpwnam($user) or next; $ENV{HOME} = (getpwuid($>))[7]; system(q#/usr/local/bin/sa-learn --force-expire#); $>=$< }' joe bob sally

That's all one line, btw--be sure to unwrap it if your mailer mangles
it. Here's what it does. For each user listed on the command line:

  - drop privileges to that user
  - set the HOME environment variable for that user
  - run sa-learn (under that user's UID)
  - become root again and try the next user

You could stick it in a file if this is something you want to run from
time to time (e.g. from a cron):

<snip>
#!/usr/local/bin/perl
## root should run this as "sa-learn-all user1 user2 user3"
for $user (@ARGV) {
    $> = getpwnam($user) or next;
    $ENV{HOME} = (getpwuid($>))[7];
    system(q#/usr/local/bin/sa-learn --force-expire#);
    $>=$<;
}
</snip>

Save it to a file and call it something like "sa-learn-all". Be sure
to make it executable (chmod 755 /path/to/sa-learn-all).  Then run it
like this from cron:

  23 5 * * * /path/to/sa-learn-all joe bob sally

Scott
-- 
Scott Wiersdorf
scott@xxxxxxxxxxxx
======================================================================
This is <vps-mail@xxxxxxxxxxxx>       <http://www.perlcode.org/lists/>
Before posting a question, please search the archives (see above URL).


Main Index | Thread Index
Match: Format: Sort by:
Search: