a trick with perl
Chris Fortune
cfortune at telus.net
Fri Jan 9 09:35:51 CET 2004
After some major quality time with my manuals, I discovered how to create a
RAM device, create temporary files in it, and feed them to bogofilter (and
several other filters via the command line). If you are the owner of a
disc-bound system with plenty of RAM, this trick could be very useful. Here
is the code to create a RAM disc (as root):
dd if=/dev/zero of=/dev/ram0 count=1440 bs=1024
mke2fs /dev/ram0
mkdir /home/username/mnt
mount /dev/ram0 /home/username/mnt
chown username /home/username/mnt # so that 'username's scripts can read
and write to it
ls -al /home/username/mnt
What I found most surprising on my system was that the RAM device was *not*
much faster than simply creating a file on disc.
# ave. time to open, print 4kb data, close and unlink a file (1000 trials)
# using disc filesystem: 0.0000653883333333333 secs.
# using RAM device: 0.0000510116666666673 secs
I have dual scsi raid, which is apparantly pretty fast. The RAM device is
only about 22% faster, but I suppose it makes a difference as the months go
by, so I may as well use it, now that it's set up.:
# create temporary file
$temp_file = "/home/username/mnt/" . rand(100) . "\.tmp";
print "$temp_file\n" if $DEBUG;
open TEMP, ">$temp_file" or die $!;
print TEMP $email_contents;
close TEMP;
# BogoFilter
$bf = `bogofilter -T < $temp_file`; # ahhh, so easy. No messy
pipes
print "BogoFilter response: $bf\n";
# Vipul's Razor
... etc...
# ClamAV
... etc...
# Pyzor
... etc...
More information about the Bogofilter
mailing list