Custom Search

Saturday, October 31, 2009

Saving Tips From Mailing Lists

Besides my constant experimentation towards always
learning more about OpenBSD, one of my other means
of accumulating tips is from the mailing lists I
subscribe to. I put together a script to save messages
from the misc@openbsd mailing list. It finds all the
messages in thread in my mutt subdirectory under Mail
and concatenates all of them to a text file. It’s
interactive and it asks you for a search pattern,
where to search, and where to save the output to.
Here’s what it looks like:

#!/bin/sh
# Filename: obsd2tips.sh – save mailing list problem
# questions and resolutions to my BSD tips folder

echo “Enter your search pattern: ”
read r

echo “Enter your search path: ”
read R

echo “Enter file to save to: ”
read i

cat `grep -l “$r” $HOME/$R/*` | \
sed ‘/Return-Path/,/X-Virus-Checker-Version/d’ >> \
$HOME/bsd/$i.txt

The stuff like Return-Path and X-Virus-Checker-Version
are stuff in my header I don’t want in the saved tip.
If it was just a single message I could strip the entire
header with a sed command, but it doesn’t work when there
is more than one message in the thread. It gets even more
complicated on the script I use to do the same thing with
my freebsd-questions mailing list threads. Here’s that
script and you will see the difference:

#!/bin/sh
# Filename: fbsd2tips.sh – save mailing list problem
# questions and resolutions to my BSD tips folder

echo “Enter your search pattern: ”
read r

echo “Enter your search path: ”
read R

echo “Enter file to save to: ”
read i

cat `grep -l “$r” $HOME/$R/*` | \
sed ‘/Return-Path/,/X-Virus-Checker-Version/d’ | \
sed ‘/freebsd-questions/d’ |sed ‘/unsubscribe/d’ >> \
$HOME/bsd/$i.txt

Depending on your MUA you will have to adjust your
filtering. I’ve been using mutt for years and do not
have any intention of switching to anything else. So,
if you’re using mutt, it will be easy to implement
for you. If you’re using some other MUA YMMV. ;)

Cheers!

Sat Oct 31 14:35:33 CDT 2009
Addendum:

Made the script a bit more interactive and helpful.
Thanks go to my friend Girish for helping me on it,
too. Here’s the new script for searching through my
misc@openbsd mail threads:

#!/bin/sh
# Filename: obsd2tips.sh – save mailing list problem
# resolutions to my BSD tips folder
found=”N”
while [ "$found" = "N" ]; do
echo “Enter your search pattern: ”
read r

echo “Enter your search path: ”
read R

echo “Enter file to save to: ”
read i

if grep $r $HOME/$R/* > /dev/null 2>&1 ;
then
cat `grep -l “$r” $HOME/$R/*` | \
sed ‘/Return-Path/,/X-Virus-Checker-Version/d’ >> \
$HOME/bsd/$i.txt
# XXX finish the program!
found=”foo”
else
echo “Can’t find it! Check your search pattern and path.”
# Rerun the search with new pattern and/or path
found=”N”
fi
done

I’d also like to add something at the end of the script where,
even after it finds what I’m looking for and writes it out to my
tips file, it will still come up and ask me if I’d like to enter
a new search. Anyone have a suggestion, please leave a comment.

Cheers!

Labels: , , ,

0 Comments:

Post a Comment

Links to this post:

Create a Link

<< Home