Last active
January 10, 2018 15:47
-
-
Save willpower232/000de99165c1a69f4f91e9f2f27f2a58 to your computer and use it in GitHub Desktop.
Output pending apt updates as a string and do something with it, good for crons. Aptitude based version of https://gist.github.com/willpower232/ebc91827347c18501030ea0bb70f1a2a
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 | |
# - just-print bypasses the sudo lock requirement | |
# - have to narrow it down to lines with brackets to avoid simulation warning that has whitespace at the start | |
# also note this will include any packages on hold, you should use apt pinning to hide them from the update process | |
UPDATES_COUNT=$(apt-get --just-print -V -u upgrade --assume-no | grep "(" | grep "^\s" | wc -l) | |
# store the hostname for later | |
HOSTNAME=$(hostname) | |
if [[ $UPDATES_COUNT -gt 0 ]]; then | |
UPDATE_STRING="Server Updates pending on $HOSTNAME: $UPDATES_COUNT" | |
# 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