#!/bin/sh
#
# Nagios plugin to check the package status on Debian based servers
# written by Gerd Koenig <geko@deb.ymc.ch>
#
# Description:
#
# This plugin will return information about the
# packages' status


cnt=$(LC_ALL=C /usr/bin/dpkg -l | grep -i -E -e '^[a-z]{2}[[:space:]]+' | grep -c -v -E -e '^(ii|rc)')
if [ $cnt -eq 0 ]; then
  message="OK"
  exit_code=0
else
  message="number of corrupt package installations: $cnt"
  exit_code=2
fi

echo $message
exit $exit_code