monitoring-scripts/check_apt_pending

34 lines
847 B
Plaintext
Raw Permalink Normal View History

2021-10-03 15:30:02 -05:00
#! /bin/bash
#
# Gets the number of pending APT package updates and returns differently
# depending on how many have yet to be applied
#
threshold_warn=10
threshold_crit=20
# https://askubuntu.com/questions/269606/apt-get-count-the-number-of-updates-available
pending="$(apt-get -q -y --ignore-hold --allow-change-held-packages --allow-unauthenticated -s dist-upgrade | \
/bin/grep ^Inst | \
wc -l)"
if [ -n "$pending" ]; then
if (( pending >= threshold_crit )); then
echo "CRITICAL - $pending package updates pending"
exit 2
2021-10-03 15:35:12 -05:00
elif (( pending >= threshold_warn )); then
2021-10-03 15:30:02 -05:00
echo "WARNING - $pending package updates pending"
exit 1
elif (( pending > 0 )); then
echo "OK - $pending package updates pending"
exit 0
else
echo "OK - No updates available"
exit 0
fi
else
echo "UNKNOWN - Unable to get pending updates"
exit 3
fi