You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@spamassassin.apache.org by Sean Kennedy <sk...@tpno.org> on 2004/05/28 23:02:48 UTC

Using spamc with find...

Hi folks, I was playing around the other day, and I came up with an 
interesting problem.

What I wanted to do was to run a Maildir directory through spamc.  I 
figured the best way to do that would be to do a find and pipe the 
results through spamc. So I came up with this

find ./ -exec spamc -r < {} \;

Which, didn't work.  Neither did...

find ./ -exec 'spamc -r < {}' \;

or

find ./ -exec spamc -r \< \{\} \;

On the first one, bash says it doesn't understand {}, and on the middle 
one it tells me it can't find a file, for which is prints out the path 
info.  If I take a copy paste from that, it works beautifully on the 
command line, individually. 

Anybody have a better way to do this, besides piping it through find? 

I apprecaite any and all help.  Thanks.

Sean

Re: Using spamc with find...

Posted by Sean Kennedy <sk...@tpno.org>.
David B Funk wrote:

>On Fri, 28 May 2004, Joe Emenaker wrote:
>
>  
>
>>David B Funk wrote:
>>
>>    
>>
>>>Try:
>>>
>>>find . -type f -print | xargs -i echo "spamc -r < {}" | sh
>>>
>>>
>>>      
>>>
>>Incidentally, "-print" is implied if you don't use "-exec" (and probably
>>a few other things). So, you can just say
>>    "find . -type f | ..."
>>    
>>
>
>That depends upon what favor of Unix you are using. You are correct
>if your "find" is a Sys-V derived version. The Berkeley BSD-4.3
>version of "find" would output -nothing- if you did not use the
>'-print' or '-ls' args (it would only set the exit code).
>
>
>  
>
Thank you folks, that did the trick.

I ran a full directory spamc scan using pipes the first time, tcp the 
second.  The first time, the scan was done in 56s.  The second time, 
with tcp, it finished in 2m15s.  Are these findings consistent with 
anybody else's results?  I'd assume that the scan would be faster with 
pipes, I just didn't realize how much faster.  ;)

Thanks again

Re: Using spamc with find...

Posted by David B Funk <db...@engineering.uiowa.edu>.
On Fri, 28 May 2004, Joe Emenaker wrote:

> David B Funk wrote:
>
> >Try:
> >
> >find . -type f -print | xargs -i echo "spamc -r < {}" | sh
> >
> >
> Incidentally, "-print" is implied if you don't use "-exec" (and probably
> a few other things). So, you can just say
>     "find . -type f | ..."

That depends upon what favor of Unix you are using. You are correct
if your "find" is a Sys-V derived version. The Berkeley BSD-4.3
version of "find" would output -nothing- if you did not use the
'-print' or '-ls' args (it would only set the exit code).


-- 
Dave Funk                                  University of Iowa
<dbfunk (at) engineering.uiowa.edu>        College of Engineering
319/335-5751   FAX: 319/384-0549           1256 Seamans Center
Sys_admin/Postmaster/cell_admin            Iowa City, IA 52242-1527
#include <std_disclaimer.h>
Better is not better, 'standard' is better. B{

Re: Using spamc with find...

Posted by Joe Emenaker <jo...@emenaker.com>.
David B Funk wrote:

>Try:
>
>find . -type f -print | xargs -i echo "spamc -r < {}" | sh
>  
>
Incidentally, "-print" is implied if you don't use "-exec" (and probably 
a few other things). So, you can just say
    "find . -type f | ..."

Also, I prefer the "-c" option, since it claims to set the exitcode. 
So... you can do a one-liner like:

for name in `find . -type f`; do if (spamc -c < $name > /dev/null); then 
echo "$name is spam"; rm "$name"; fi; done

I'm not certain that this doesn't work the OPPOSITE of how it should (as 
written, it might delete all of the HAM), so TEST it without the "rm" 
first. Also, you can replace the "rm" with any set of stuff you want.... 
you can quarantine the message, add it to a zip, or whatever.

Re: Using spamc with find...

Posted by David B Funk <db...@engineering.uiowa.edu>.
On Fri, 28 May 2004, Paul Makepeace wrote:

> Je 2004-05-28 22:02:48 +0100, Sean Kennedy skribis:
> > Hi folks, I was playing around the other day, and I came up with an
> > interesting problem.
> >
> > What I wanted to do was to run a Maildir directory through spamc.  I
> > figured the best way to do that would be to do a find and pipe the
> > results through spamc. So I came up with this
> >
> > find ./ -exec spamc -r < {} \;
>
[snip..]

> It's hard (impossible?) to use xargs as spamc is a pure filter, i.e.
> doesn't take a file as an arg :-/
>
> If it did you could say,
>
>   find . -type f | xargs -i spamc -r {}
>
> ..which would have a bunch of other advantages like being able to use
> find -print0 | xargs -0 for  wackily named files, e.g. `a la sa-exim.

For difficult to "xargs" kinds of things (commands that involve shell
I/O redirection, wild cards, etc) try building up a shell command line
and feed it into another shell. (Think of it as dynamically creating
shell scripts ;).

Try:

find . -type f -print | xargs -i echo "spamc -r < {}" | sh

This also has the advantage that if you leave off the final "| sh"
you can 'dry run' the thing to make sure that it will do what you
intend. (good if you're doing destructive kinds of things like
'rm' or 'mv' ;)

-- 
Dave Funk                                  University of Iowa
<dbfunk (at) engineering.uiowa.edu>        College of Engineering
319/335-5751   FAX: 319/384-0549           1256 Seamans Center
Sys_admin/Postmaster/cell_admin            Iowa City, IA 52242-1527
#include <std_disclaimer.h>
Better is not better, 'standard' is better. B{

Re: Using spamc with find...

Posted by Paul Makepeace <ap...@paulm.com>.
Je 2004-05-28 22:02:48 +0100, Sean Kennedy skribis:
> Hi folks, I was playing around the other day, and I came up with an 
> interesting problem.
> 
> What I wanted to do was to run a Maildir directory through spamc.  I 
> figured the best way to do that would be to do a find and pipe the 
> results through spamc. So I came up with this
> 
> find ./ -exec spamc -r < {} \;

Try,

  for i in `find . -type f`; do spamc -r < $i; done

It's hard (impossible?) to use xargs as spamc is a pure filter, i.e.
doesn't take a file as an arg :-/

If it did you could say,

  find . -type f | xargs -i spamc -r {}

..which would have a bunch of other advantages like being able to use
find -print0 | xargs -0 for  wackily named files, e.g. `a la sa-exim.

HTH,
Paul

-- 
Paul Makepeace ................................  http://paulm.com/ecademy

"What is a relative meaning for relativity? Yet another option."
   -- http://paulm.com/toys/surrealism/