If you’ve been messing with Linux for a while you’ve no doubt seen screens like the above a million times. But for me it’s never been enough. If you have lots of boxes it’s possible to forget about them, so finding out that you have security updates when you log in isn’t proactive enough.
So let me save you 37 Googles. Here’s how to find out if your Ubuntu box needs security updates applied.
Install apt-notifier to enable the check
bash
apt install update-notifier
Check to see how many security updates you have
bash
/usr/lib/update-notifier/apt-check 2>&1 | cut -d ‘;’ -f 2
Install ssmpt so you can send email from the command line
bash
apt install ssmtp
Then create a script in /etc/cron.hourly to check if there are updates available
Don’t forget to make the script executable.
bash
SECUPDATES=/usr/lib/update-notifier/apt-check 2>&1 | cut -d ';' -f 2
if (( $SECUPDATES > 0 )); then
ssmtp [email protected] <echo "There are security updates on cat /etc/hostname." | ssmtp -s "Updates on cat /etc/hostname"
elseexit;
fi
Now you will receive an email whenever your Ubuntu box has security updates available!