Skip to content

Instantly share code, notes, and snippets.

@willpower232 willpower232/
Last active Jan 10, 2018

What would you like to do?
Output pending apt updates as a string and do something with it, good for crons. Aptitude based version of
# 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
if [[ $UPDATES_COUNT -gt 0 ]]; then
# slack through a webhook to a channel
#curl --data $UPDATE_STRING '' > /dev/null 2>&1
# regular email
#echo $UPDATE_STRING | mail -s "Package Updates for $HOSTNAME" ""
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.