sabato 27 dicembre 2008

Mutt and nbSMTP

Not so long ago I installed in different locations a few PCs as servers.
I choose Ubuntu server edition 8.0.4 LTS (Long-Term Support) aka Hardy Heron, the latest LTS version available from Canonical.
I prefer the hard way, without the GUI. Sorry, I don't like Linux GUIs ;-)
That way I can control what is installed, and install just what is really useful for that particular machine, leaving precious resources to services that need them. There is also another advantage. Limiting possible security issues.
One of these servers, in particular, has to manage the nightly backup of another server, this time a Windows 2003, via rsync.
I created a bash script to do the job and scheduled it with crontab.
The script, during the process, creates a report that is saved as a zip archive when the work is finished.
I was wondering how could I get that file to check everything was fine, without remotely access the server.
The obvious response was. By e-mail.
I started hunting for information in search for the most elegant solution with the minimum impact on the system.

What I found, and I picked, to achieve my goal, are these two little gems.

Mutt "a small but very powerful text-based mail client for Unix operating systems" and No Brainer SMTP nbSMTP "a simple MTA to send your mails to another mail server via SMTP".

First step. Retrieve and install the two packages. In Ubunto the apt-get command is aimed at that.

sudo apt-get install mutt
sudo apt-get install nbsmtp

I created a user specific .muttrc containing these lines

# No need to keep copy of the outgoing messages
set copy=no
# Some changes to the message headers
set hdrs=yes
my_hdr From: Me the sender <>
# How to invoke nbsmtp
set sendmail="/usr/bin/nbsmtp -f -d -h"

and to complete the work, at the end of the bash script that is supposed to make the backup, I've added the line in charge of sending the message

mutt -s "Backup report" -a < messagebody.txt

"Backup report" - is the subject of the message (option -s) - is the attachment (option -a) - is the recipient
messagebody.txt - is the main body of the e-mail (read message from the file messagebody.txt)

The file messagebody.txt could be anything you want to insert as the body of the message being sent.

Last but not least :-) I've also inserted this line into crontab file


to avoid error warning in log file
nbSMTP does not support the -o arguments from sendmail, ignoring them

because every time a croned job is executed mail is sent to the owner of the crontab

Nessun commento: