Monday, January 08, 2007

Adding dino description signature on thunderbird

Here's something I've wanted for a long time now, and was too lazy to write one - a script that adds random dinosaur descriptions as your signature to thunderbird mail.

Before you go on to accuse me of blasphemy for not using perl, here's the reason - I didn't want to. Why perl when you can bash :D

1. Get the list of dinosaurs from wikipedia.
bash $ wget -o /tmp/dinolist.txt http://en.wikipedia.org/wiki/List_of_dinosaurs;

2. Strip off html tags
bash $ cat /tmp/dinolist/.txt | grep "<li> < i> < a href="%5C%22/wiki/%22" | cut -d"\"" -f 2 | cut -d"/" -f 3 | tee dinosaurlist.txt

3. Generate the signature

bash $ vim gen_signature.sh
#!/bin/bash
count=`cat dinosaurlist.txt | wc -l`
random=$RANDOM
let dinonum=$RANDOM%count
xyz=(`cat dinosaurlist.txt`)
dinoname=${xyz[$dinonum]}
echo $dinoname
lynx --dump http://en.wikipedia.org/wiki/${dinoname} | egrep -A 20 "\[[0-9]*\]Binomial name" | sed 's/\[[0-9]*\]//g' > "/home/ishwar/.thunderbird/signature.txt"

text=`cat /home/ishwar/.thunderbird/signature.txt`

if [ -z "$text" ]
then
lynx --dump http://en.wikipedia.org/wiki/${dinoname} | egrep -A 20 "\[[0-9]*\]Species" | sed 's/\[[0-9]*\]//g' > "/home/ishwar/.thunderbird/signature.txt"
fi


4. Change the signature once every five minutes.
bash $ cat /etc/crontab
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/

# run-parts
*/5 * * * * ishwar /home/ishwar/.thunderbird/gen_signature.sh

Accepted, this is not the most elegant script. But it makes me happy.



3 comments:

spo0nman said...

It is polite to keep your email signature below 4 lines.

Ishwar said...

But there is so much to say about dinosaurs :|

Unknown said...

CooL!