Skip to content

Instantly share code, notes, and snippets.

@ferbass
Last active August 16, 2023 02:52
Show Gist options
  • Save ferbass/0c5cddc47e7603709c12c78b73b3b6b7 to your computer and use it in GitHub Desktop.
Save ferbass/0c5cddc47e7603709c12c78b73b3b6b7 to your computer and use it in GitHub Desktop.
Check for Linux host (Debian) available updates and post to slack
#!/usr/bin/env bash
set -o errexit
set -o nounset
set -o pipefail
if [[ "${TRACE-0}" == "1" ]]; then
set -o xtrace
fi
# Check for upgradable packages
check=$(apt-get upgrade --simulate 2>/dev/null )
if [[ $check == *"0 upgraded"* ]]
then
echo "Nothing to do for today."
exit
fi
send_slack_notification() {
slack_webhook_url="YOUR_SLACK_WEBHOOK"
LIST=$(apt list --upgradable) 2>/dev/null
message="$(hostname) Updates are available.
\n
$LIST
\n
Run 'sudo apt-get upgrade' to apply them."
curl -X POST -H 'Content-type: application/json' --data "{\"text\":\"$message\"}" "$slack_webhook_url"
}
send_slack_notification
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment