Skip to content

Instantly share code, notes, and snippets.

@willpower232 willpower232/yum-check.sh
Last active Jan 10, 2018

Embed
What would you like to do?
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
#!/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
You can’t perform that action at this time.