Skip to content

Instantly share code, notes, and snippets.

@johnteslade
Created February 15, 2015 10:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnteslade/0661531c638a2229f5cd to your computer and use it in GitHub Desktop.
Save johnteslade/0661531c638a2229f5cd to your computer and use it in GitHub Desktop.
Nagios plugin to check if a machine has packages that apt can autoremove
#!/bin/bash
# Nagios plugin to check if a machine has packages that apt can autoremove
# Author: John Slade (http://jtes.net)
AUTOREM_OUTPUT=$(apt-get --dry-run autoremove)
TO_REMOVE=$(echo $AUTOREM_OUTPUT | perl -pe 's/^.*?, (\d*) to remove.*$/$1 to remove/g')
if echo $AUTOREM_OUTPUT | grep -q "0 to remove"; then
# no pacakges to remove (0=OK)
echo "OK: no reboot required"
exit 0
else
# some packages to remove (1=WARN)
echo "WARNING: $TO_REMOVE"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment