Shell Scripting

Training SpamAssassin for Effective Spam Removal

Intro

SpamAssassin is a tool to remove Spam from incoming email. The following describes a way of training Spam Assassin to be more effective.

Background

Email is stored within Cyrus, and mail that gets through SpamAssassin into a user's inbox is then moved to the "put_spam_here" folder by the user.

This script is run hourly, empties the "put_spam_here" folder, and hopefully trains spamassassin to catch more spam.

lockfile-progs

Lockfile-progs

Normally when writing a shell script and not wanting more than one of 'it' to run at a time, I use something like :

LOCK=/tmp/something
if [ -f $LOCK ]; then
    # lock file already exists....
    exit 1
fi

trap "/bin/rm $LOCK" EXIT SIGKILL SIGTERM SIGQUIT
touch $LOCK
# rest of script here

The other day, I went to create yet-another-script and this time stumbled onto lockfile-progs, in which case my locking algorithm can be slightly more elegant like :

BASH PS1

I've created a quick howto which might help someone who is suffering from a BASH PS1 prompt which gets too unwieldy when your `pwd` is quite long. see here

Customising the BASH prompt

intro:
The Unix BASH shell is customisable. This covers one way of setting your PS1 so it doesn't get too long when in a deeply nested file hiearchy. It assumes you already know what PS1 is etc.

subject:
bash PS1 prompt customisation

How to count

When writing bash shell scripts, I keep forgetting how to do arithmetric.... so here is a reminder for me ....

#!/bin/bash

# Either :
f=10
let f=f+1
echo "$f is now 11"

# Or :
f=10
f=$(($f+1))
echo "$f is now 11"

# More advanced :

# (Random number between 0 and 8 inclusive)
f=`perl -le 'print int rand 9'` 
echo "$(($f+10)), $(($f+20)), $(($f+30)) prints e.g. 2, 14, 24, 24"

End memory jogging post.

Syndicate content