Skip to content

Instantly share code, notes, and snippets.

@pcrockett
Created July 13, 2019 14:30
Show Gist options
  • Save pcrockett/c0cf4f509eed0fb48e7e02d25c7af846 to your computer and use it in GitHub Desktop.
Save pcrockett/c0cf4f509eed0fb48e7e02d25c7af846 to your computer and use it in GitHub Desktop.
Unattended security updates with healthcheck.io monitoring
#!/bin/bash
#
# sudo apt install unattended-upgrades
#
# crontab example:
# 0 4 * * * /home/user/unattended-upgrade.sh >/home/user/upgrade-log 2>&1
#
# https://vaneyckt.io/posts/safer_bash_scripts_with_set_euxo_pipefail/
set -Eeuo pipefail
if unattended-upgrade; then
curl -fsS --retry 3 https://hc-ping.com/MONITOR_ID_HERE > /dev/null
if [ -f "/var/run/reboot-required" ]; then
shutdown now -r
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment