Unattended-upgrades mail only on error or reboot?
I have unattended-upgrades installed on several servers, some version 12, some 14. I would like to enable MailOnlyOnError for them but would still like to receive email notices when an update requires reboot.
Will I still receive "reboot required" notices with MailOnlyOnError enabled?
Thanks!
Here is a solution based on an answer in this discussion.
The trick is that the request for a reboot is indicated by the presence of the file /var/run/reboot-required
.
Create a file /usr/local/sbin/email_update_required
with the content
if [ -f /var/run/reboot-required ]; then
echo "A reboot is required following updates to server `hostname`" | mail -s "Reboot Required" <mail-address>
fi
Adjust <mail-address>
(for example to root
or your personal email address). Check the permissions and make the file executable.
Put the following line into your root crontab (sudo crontab -e
)
00 08 * * * /usr/local/sbin/email_update_required
(It runs the email_update_required script every day at 8 o’clock, adjust as needed.)
I've applied the above method to a Ubuntu 14.04 server with unattended-upgrades
and MailOnlyOnError true"
, and it works.
Still, it would be nice to have a more "official" Ubuntu or unattended-upgrades way to get those notification mails. A switch similar to MailOnlyOnError
would be great.