You can configure the Slug to send you email alerts when bad things happen, like failed backups and full disks. This is done through the Admin webpage and you can specify the destination email address and the subject line of the email. However, I have never gotten my Slug to send me email with via the normal mechanisms. This is the alert process as I've gleaned from doing
strings on various binaries and libraries:
- A script which wants to issue an email alert calls
set_log calls some library routine in
- This library routine calls
/usr/sbin/smtpclient which is a binary SMTP mail client.
The sendmail server at my ISP blocks email sent by the standard NSLU2 smtpclient on my Slug because it appears Comcast-issued IP addresses are spam black-listed. If the Linksys-provided smtpclient could be instructed to use a mail relay (Comcast provides one) it shouldn't be blocked as spam, but unfortunately the -S argument of smtpclient, to specify a mail relay host, is not supported. However, nail, an available ipkg package, does support mail relays. Here are the steps to use nail instead of the Linksys-provided smtpclient to send alerts:
- Install nail (I got these steps from Nail)
ipkg install nail
- Create a
/root/.mailrc (or where ever your root's homedir is) containing
- Create wrapper script for nail which translates smtpclient parameters to nail parameters and passes along whatever comes through stdin. I store this script in
/opt/local/bin/nail_wrapper. I didn't want to store my wrapper script in the original location for first time I did that I forgot about it and my script got wiped out when I upgraded from Unslung 3.18 to 5.5. Script is listed below.
- Rename the original smtpclient program
mv /usr/sbin/smtpclient /usr/sbin/smtpclient.orig
- Create a symbolic link pointing to the new script
ln -s /opt/local/bin/nail_wrapper /usr/sbin/smtpclient
You can test the new mechanism by calling
/usr/sbin/set_log backup 0 1
This will send you a bogus email alert about a backup failure. The "backup" keyword is the name of a stanza in
/etc/cgi_msg. The last number, 1, is an index to the actual error message in the backup stanza. The second number, 0, tells set_log to send an email rather than just log a message in /var/log/server.log. If it were a 1, no email would be sent. Try
man set_log for a few more details.
This script needs to translate the arguments liblog.so provides to smtpclient to those appropriate for nail. liblog.so calls smtpclient like this, sending the text of the email on standard input:
/usr/sbin/smtpclient -s <subject> -f admin@<IP of slug> <to_address>
<to_address> are provided in the NSLU2 Admin webpage. With this script I am basically throwing away the -f argument, which does something different with nail. E.g:
/opt/bin/nail -s <subject> <to_address>
The script logs what it does to
/var/log/mail_alert.log. You can take this out if you don't like it. Also, because I was lazy and used getopts, the script requires bash to be installed. Also, make sure the script has execute permissions. Mine is 755 owned by root.
I would appreciate any feedback if this Howto is useful to you. Enjoy!
while getopts s:f: arg; do
case $arg in
?) echo "Syntax error"
shift $(($OPTIND - 1))
date >> $log_file
echo "Subject: $subject" >> $log_file
echo "From: $from_addr" >> $log_file
echo "To: $to_addr" >> $log_file
cat - | tee -a $log_file | /opt/bin/nail -s "$subject" "$to_addr"