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
#!/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