1
0
mirror of https://github.com/librenms/librenms-agent.git synced 2024-05-09 09:54:52 +00:00
Florian Beer fac01628a0 Add Debian and make update call more robust
- Debian based systems need to update the index before being able to report upgradable packages.
- Debian old-stable doesn't have `apt` yet and Ubuntu 14.04 emits the following warning when using `apt` in a script:
`WARNING: /usr/bin/apt does not have a stable CLI interface yet. Use with caution in scripts.`

By using `apt-get`, issuing a `update` call first and then counting the result of `grep 'Inst'`, this script now works on Debian 7, Debian 8, Ubuntu 14.04 and Ubuntu 16.04.
2016-08-03 04:51:35 +02:00

48 lines
1.3 KiB
Bash
Executable File

#!/bin/bash
################################################################
# copy this script to somewhere like /opt and make chmod +x it #
# edit your snmpd.conf and include #
# extend osupdate /opt/os-updates.sh #
# restart snmpd and activate the app for desired host #
################################################################
BIN_AWK='/usr/bin/awk'
BIN_WC='/usr/bin/wc'
CMD_WC='-l'
BIN_ZYPPER='/usr/bin/zypper'
CMD_ZYPPER='lu'
BIN_YUM='/usr/bin/yum'
CMD_YUM='check-update'
BIN_APT='/usr/bin/apt-get'
CMD_APT='-s upgrade'
CMD_UPDATE='-qq update'
#general check for os based on /etc/os-release
if [ -f /etc/os-release ]; then
OS=`$BIN_AWK -F= '/^ID=/{print $2}' /etc/os-release`
if [ $OS == "opensuse" ]; then
UPDATES=`$BIN_ZYPPER $CMD_ZYPPER | $BIN_WC $CMD_WC`
if [ $UPDATES -gt 3 ]; then
echo $(($UPDATES-3));
else
echo "0";
fi
elif [ $OS == "\"centos\"" ]; then
UPDATES=`$BIN_YUM $CMD_YUM | $BIN_WC $CMD_WC`
if [ $UPDATES -gt 6 ]; then
echo $(($UPDATES-6));
else
echo "0";
fi
elif [ $OS == "ubuntu" ] || [ $OS == "debian" ]; then
`$BIN_APT $CMD_UPDATE`
UPDATES=`$BIN_APT $CMD_APT | grep 'Inst' | $BIN_WC $CMD_WC`
if [ $UPDATES -gt 1 ]; then
echo $UPDATES;
else
echo "0";
fi
fi
else
echo "0";
fi