Last active
August 16, 2023 02:52
-
-
Save ferbass/0c5cddc47e7603709c12c78b73b3b6b7 to your computer and use it in GitHub Desktop.
Check for Linux host (Debian) available updates and post to slack
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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