Created
February 15, 2015 10:39
-
-
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
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 | |
# 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