Last active
January 10, 2018 15:49
-
-
Save willpower232/ebc91827347c18501030ea0bb70f1a2a to your computer and use it in GitHub Desktop.
Output pending yum updates as a string and do something with it, good for crons. Based on https://relativkreativ.at/articles/simple-update-notifications-for-your-centos-redhat-server
This file contains 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
#!/bin/bash | |
# count package updates by the number of lines | |
# note that this will include packages pending replacement because of needing system reboot | |
UPDATES_COUNT=$(yum check-update --quiet | grep -v "^$" | wc -l) | |
# count security updates with a substring | |
SECURITY_UPDATES=$(yum --debuglevel 2 --security check-update 2>/dev/null | grep -P '(?<! 0 packages) available$' | cut -d ',' -f 1) | |
# store the hostname for later | |
HOSTNAME=$(hostname) | |
if [[ $UPDATES_COUNT -gt 0 ]]; then | |
UPDATE_STRING="Server Updates pending on $HOSTNAME: $UPDATES_COUNT, $SECURITY_UPDATES" | |
# slack through a webhook to a channel | |
#curl --data $UPDATE_STRING 'https://WHATEVER.slack.com/services/hooks/slackbot?token=TOKEN&channel=%23CHANNEL' > /dev/null 2>&1 | |
# regular email | |
#echo $UPDATE_STRING | mail -s "Package Updates for $HOSTNAME" "email@example.com" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment