
¿Existe la posibilidad de que el servidor Ubuntu 20.04 LTS pueda enviar un correo a direcciones de correo electrónico específicas cuando se ha instalado una actualización que requiere reiniciar el servidor?
Entonces, por ejemplo, cuando el archivo /var/run/reboot-required.pkgs existe, envía un correo a los administradores para que puedan reiniciar.
He buscado en Google pero no puedo encontrar un tutorial sencillo para esto.
Respuesta1
Pruebe /etc/apt/apt.conf.d/50unattended-upgrades
// Send email to this address for problems or packages upgrades
// If empty or unset then no email is sent, make sure that you
// have a working mail setup on your system. A package that provides
// 'mailx' must be installed. E.g. "[email protected]"
Unattended-Upgrade::Mail "[email protected]";
// Set this value to "true" to get emails only on errors. Default
// is to always send a mail if Unattended-Upgrade::Mail is set
Unattended-Upgrade::MailOnlyOnError "false";
En realidad, esa es la parte fácil. A continuación, debemos configurar un sistema postal liviano para sacar el correo electrónico del servidor y entregárselo a usted.
Aquí hay una forma de hacerlo:
sudo apt install msmtp msmtp-mta bsd-mailx
Archivo de configuración:/root/.msmtprc
account your_label_here
host smtp.example.com
port 465
from root@your_machine.your_domain
user [email protected] (your email)
password your_smtp_password
auth on
tls on
tls_starttls off
tls_certcheck off
logfile /root/.msmtp.log
account default : your_label_here
Comando de prueba:
echo "This is the email body" > /tmp/body.txt && sudo mailx -s "This is the subject" [email protected] < /tmp/body.txt; rm /tmp/body.txt
Respuesta2
Gracias, seguí el tutorial y edité un cronjob para esto, de hecho, como usuario root, creé el archivo de configuración /root/.msmtprc.
account your_label_here
host smtp.example.com
port 465
from root@your_machine.your_domain
user [email protected] (your email)
password your_smtp_password
auth on
tls on
tls_starttls off
tls_certcheck off
logfile /root/.msmtp.log
account default : your_label_here
Luego creé un archivo en /etc/cron.hourly/reboot-check
#!/usr/bin/env bash
if [ -f /var/run/reboot-required ]; then
echo "A reboot is required following updates to server <TestServer> the machine will auto reboot in 1h" > /tmp/body.txt && sudo mailx -s "Reboot Required" [email protected] < /tmp/body.txt; rm /tmp/body.txt
fi
Y cuando la máquina tiene una actualización que requiere un reinicio y crea el archivo /var/run/reboot-required, me envía un correo electrónico para notificarme del reinicio.