Monday, February 7, 2011

Email Available Updates for Debian

Before you proceed below please check:
  • Simple apt daily update script, see here.
  • Configure exim4 to send messages by smarthost, no local mail, see here.
We are going enhance daily update script by ability to send a list of new updates to mail.
#!/bin/sh

mailto=debian-updates@dev.local

# Download only; package files are only retrieved, not 
# unpacked or installed.
apt-get -dqq update
apt-get -dyqq upgrade

has_upgrades=$(apt-get -s upgrade | grep ^Inst)
if [ "$has_upgrades" ] ; then
    echo "$has_upgrades" | mail -s \
    "Updates for $(hostname) on $(date +%Y-%m-%d)" \
    $mailto
fi
Alternatively consider using apticron, read more here.

Configure exim4 to send messages by smarthost, no local mail

This option of exim4 configuration is suitable for a client system which is not responsible for a local e-mail domain. All locally generated e-mail is sent to the smarthost.
  • Smarthost FQDN: mail.dev.local
  • Client: deby01.dev.local
Here are few simple steps to configure:
  1. The easiest way is to reconfigure exim4-config package:
    dpkg-reconfigure exim4-config
    
  2. General type of mail configuration:
       mail sent by smarthost; no local mail
    System mail name:
       deby01.dev.local
    IP-addresses to listen on for incoming SMTP connections:
       127.0.0.1
    Other destinations for which mail is accepted:
       deby01.dev.local
    Visible domain name for local users:
       deby01.dev.local
    IP address or host name of the outgoing smarthost:
       mail.dev.local
    Keep number of DNS-queries minimal (Dial-on-Demand)?
       No
    Split configuration into small files?
       No
    
Let verify it is working:
echo "test message" | mail -s "test" user1@dev.local
... exim4 log (file /var/log/exim4/mainlog):
1PmoNq-0001or-55 <= root@deby01.dev.local H=deby01.dev.local (localhost) [192.168.XX.XXX] P=esmtps X=TLS1.0:RSA_AES_256_CBC_SHA1:32 S=715 id=E1PmoNq-0001f6-08@localhost
1PmoNq-0001or-55 => user1  R=local_user T=maildir_home
1PmoNq-0001or-55 Completed
At this point user1 should be able to receive your test message.