Thursday, April 03, 2008

Quick Bash Pointer

While writing a Bash script today, I came across an interesting situation.

I had gathered some output into a variable and I wanted to email those results to myself.

Typically you just use the mail command, specify a subject, and add a to address. Then just pipe in a file which will be used for the body text of the email.

However, I didn't have results in a file. I had them in a variable in memory. So rather than create a temp file and use the traditional approach, a friend of mine showed me the following approach which seems cleaner.

mail -s "subject" "to address" <<eof
$RESULT
eof


This will send everything after '<<eof' up to the next 'eof' to the mail command via stdin. More information can be found here about the usage of eof.

Original suggestion for this approach was taken from the following link, in the comments section.

Tuesday, April 01, 2008

MailScanner Cron Jobs (Ubuntu 6.06.2 LTS w/ Mailscanner 4.68.8-1)

I recently performed a MailScanner upgrade on a mail server that I maintain, and I noticed that afterwards I was receiving tons of messages from the MailScanner cron jobs that were running.

The messages didn't indicate any problems, just that things were running smoothly. While this is great information, I really only need to know when there is a problem so I can correct it. Anything else will just clutter my inbox or be filtered to the trash.

My initial thought was to just pipe the output to /dev/null and forget about it. However if I did this I would no longer receive emails alerting me of problems, which I need to get.

The three scripts that were causing a problem are check_mailscanner, update_phishing_sites, and update_bad_phishing_sites.

The check_mailscanner has an easy fix, and that is to just add a -q parameter to the cron entry that calls the script. This will suppress the positive output.

The other two scripts I had to manually edit. I commented out the line calling wget and modified the command to call curl to have the --silent and --show-error options.

Not sure this was the best way to fix the problem, but it has seemed to do the trick. Other suggestions are welcome.


update_phishing_sites

#wget http://www.mailscanner.info/phishing.safe.sites.conf.master || \
curl --silent --show-error -O http://www.mailscanner.info/phishing.safe.sites.conf.master || \
( logger -p mail.warn -t update.phishing.sites Cannot find wget or curl, update failed. ; echo Cannot find wget or curl to do phishing sites update. ; exit 1 )

update_bad_phishing_sites

#wget http://www.mailscanner.eu/phishing.bad.sites.conf.master || \
curl --silent --show-error -O http://www.mailscanner.eu/phishing.bad.sites.conf.master || \
( logger -p mail.warn -t update.phishing.sites Cannot find wget or curl, update failed. ; echo Cannot find wget or curl to do phishing bad sites update. ; exit 1 )