Page MenuHomePhabricator
Paste P6365

report-pending-upgrades.sh
ActivePublic

Authored by aborrero on Nov 22 2017, 1:54 PM.
#!/bin/bash
if [ "$(id -u)" != "0" ] ; then
echo "E: root required" >&2
exit 1
fi
get_binary()
{
BINARY=$(which $1)
if [ ! -x "$BINARY" ] ; then
echo "E: no $1 binary found" >&2
exit 1
fi
echo $BINARY
}
set -e
APT_GET=$(get_binary apt-get)
APT_SHOW_VERSIONS=$(get_binary apt-show-versions)
UNATTENDED_UPGRADES=$(get_binary unattended-upgrades)
set +e
echo "I: updating package cache"
$APT_GET update >/dev/null
APT_SHOW_VERSIONS_OUTPUT=$($APT_SHOW_VERSIONS | grep upgradeable)
n1=$(echo "$APT_SHOW_VERSIONS_OUTPUT" | grep -v ^$ | wc -l)
UNATTENDED_UPGRADES_OUTPUT=$($UNATTENDED_UPGRADES --dry-run -v -d | grep "Packages that will be upgraded" | awk -F':' '{print $2}' | grep -v ^[[:space:]]*$)
n2=$(echo "$UNATTENDED_UPGARDES_OUTPUT" | grep -v ^$ | wc -l)
if [ "$n1" != "0" ] ; then
echo "I: upgradeable packages: $n1"
echo
echo "$APT_SHOW_VERSIONS_OUTPUT"
echo
fi
if [ "$n2" != "0" ] ; then
echo "I: upgradeable packages by unattended-upgrades: $n2"
echo
echo "$UNATTENDED_UPGARDES_OUTPUT"
echo
fi
echo "I: $n1 upgradeable packages, $n2 upgradeable packages by unatteneded-upgrades"

Event Timeline

aborrero created this paste.Nov 22 2017, 1:54 PM
aborrero edited the content of this paste. (Show Details)Nov 22 2017, 2:07 PM

Example output in debian buster testing:

I: updating package cache
I: upgradeable packages: 2

libgl1-mesa-glx:amd64/testing 13.0.6-1+b2 upgradeable to 17.2.5-1
libglapi-mesa:amd64/testing 13.0.6-1+b2 upgradeable to 17.2.5-1

I: 2 upgradeable packages, 0 upgradeable packages by unatteneded-upgrades

Example output in tools-exec-1403 (ubuntu trusty)

aborrero@tools-exec-1403:~$ sudo  bash report-pending-upgrades.sh 
I: updating package cache
I: upgradeable packages: 128

accountsservice:amd64/trusty-updates 0.6.35-0ubuntu7.1 upgradeable to 0.6.35-0ubuntu7.3
base-files:amd64/trusty-updates 7.2ubuntu5.1 upgradeable to 7.2ubuntu5.5
bash-completion:all/trusty-updates 1:2.1-4 upgradeable to 1:2.1-4ubuntu0.2
bsdutils:amd64/trusty-updates 1:2.20.1-5.1ubuntu20.3 upgradeable to 1:2.20.1-5.1ubuntu20.9
cloud-guest-utils:all/trusty-updates 0.27-0ubuntu9 upgradeable to 0.27-0ubuntu9.2
cloud-image-utils:all/trusty-updates 0.27-0ubuntu9 upgradeable to 0.27-0ubuntu9.2
cloud-init:all/trusty-updates 0.7.5-0ubuntu1.18 upgradeable to 0.7.5-0ubuntu1.22
cloud-utils:all/trusty-updates 0.27-0ubuntu9 upgradeable to 0.27-0ubuntu9.2
dbus:amd64/trusty-updates 1.6.18-0ubuntu4.4 upgradeable to 1.6.18-0ubuntu4.5
dbus-x11:amd64/trusty-updates 1.6.18-0ubuntu4.4 upgradeable to 1.6.18-0ubuntu4.5
dh-python:all/trusty-updates 1.20140128-1ubuntu8 upgradeable to 1.20140128-1ubuntu8.2
distro-info-data:all/trusty-updates 0.18ubuntu0.7 upgradeable to 0.18ubuntu0.8
dpkg:amd64/trusty-updates 1.17.5ubuntu5.6 upgradeable to 1.17.5ubuntu5.7
dpkg-dev:all/trusty-updates 1.17.5ubuntu5.6 upgradeable to 1.17.5ubuntu5.7
e2fslibs:amd64/trusty-updates 1.42.9-3ubuntu1.2 upgradeable to 1.42.9-3ubuntu1.3
e2fsprogs:amd64/trusty-updates 1.42.9-3ubuntu1.2 upgradeable to 1.42.9-3ubuntu1.3
fonts-lyx:all/trusty-updates 2.0.6-1build1 upgradeable to 2.0.8.1-0ubuntu1
gcc-4.9-base:amd64/trusty-updates 4.9.1-0ubuntu1 upgradeable to 4.9.3-0ubuntu4
gdb:amd64/trusty-security 7.7.1-0ubuntu5~14.04.2 upgradeable to 7.7.1-0ubuntu5~14.04.3
grub-common:amd64/trusty-updates 2.02~beta2-9ubuntu1.6 upgradeable to 2.02~beta2-9ubuntu1.14
ifupdown:amd64/trusty-updates 0.7.47.2ubuntu4.1 upgradeable to 0.7.47.2ubuntu4.4
init-system-helpers:all/trusty-updates 1.14 upgradeable to 1.14ubuntu1
initramfs-tools:all/trusty-updates 0.103ubuntu4.2 upgradeable to 0.103ubuntu4.9
initramfs-tools-bin:amd64/trusty-updates 0.103ubuntu4.2 upgradeable to 0.103ubuntu4.9
initscripts:amd64/trusty-updates 2.88dsf-41ubuntu6 upgradeable to 2.88dsf-41ubuntu6.3
iproute2:amd64/trusty-updates 3.12.0-2 upgradeable to 3.12.0-2ubuntu1
irqbalance:amd64/trusty-updates 1.0.6-2ubuntu0.14.04.1 upgradeable to 1.0.6-2ubuntu0.14.04.4
isc-dhcp-client:amd64/trusty-updates 4.2.4-7ubuntu12.4 upgradeable to 4.2.4-7ubuntu12.10
isc-dhcp-common:amd64/trusty-updates 4.2.4-7ubuntu12.4 upgradeable to 4.2.4-7ubuntu12.10
klibc-utils:amd64/trusty-updates 2.0.3-0ubuntu1 upgradeable to 2.0.3-0ubuntu1.14.04.3
krb5-locales:all/trusty-updates 1.12+dfsg-2ubuntu5.2 upgradeable to 1.12+dfsg-2ubuntu5.3
libaccountsservice0:amd64/trusty-updates 0.6.35-0ubuntu7.1 upgradeable to 0.6.35-0ubuntu7.3
libavahi-client3:amd64/trusty-updates 0.6.31-4ubuntu1 upgradeable to 0.6.31-4ubuntu1.1
libavahi-common-data:amd64/trusty-updates 0.6.31-4ubuntu1 upgradeable to 0.6.31-4ubuntu1.1
libavahi-common3:amd64/trusty-updates 0.6.31-4ubuntu1 upgradeable to 0.6.31-4ubuntu1.1
libavahi-glib1:amd64/trusty-updates 0.6.31-4ubuntu1 upgradeable to 0.6.31-4ubuntu1.1
libblkid1:amd64/trusty-updates 2.20.1-5.1ubuntu20.3 upgradeable to 2.20.1-5.1ubuntu20.9
libcdt5:amd64/trusty-updates 2.36.0-0ubuntu3.1 upgradeable to 2.36.0-0ubuntu3.2
libcgmanager0:amd64/trusty-updates 0.24-0ubuntu7.2 upgradeable to 0.24-0ubuntu7.5
libcgraph6:amd64/trusty-updates 2.36.0-0ubuntu3.1 upgradeable to 2.36.0-0ubuntu3.2
libcomerr2:amd64/trusty-updates 1.42.9-3ubuntu1.2 upgradeable to 1.42.9-3ubuntu1.3
libcups2:amd64/trusty-updates 1.7.2-0ubuntu1.7 upgradeable to 1.7.2-0ubuntu1.8
libcupsimage2:amd64/trusty-updates 1.7.2-0ubuntu1.7 upgradeable to 1.7.2-0ubuntu1.8
libdbus-1-3:amd64/trusty-updates 1.6.18-0ubuntu4.4 upgradeable to 1.6.18-0ubuntu4.5
libdpkg-perl:all/trusty-updates 1.17.5ubuntu5.6 upgradeable to 1.17.5ubuntu5.7
libgcc1:amd64/trusty-updates 1:4.9.1-0ubuntu1 upgradeable to 1:4.9.3-0ubuntu4
libgl1-mesa-glx:amd64/trusty-updates 10.1.3-0ubuntu0.4 upgradeable to 10.1.3-0ubuntu0.6
libglapi-mesa:amd64/trusty-updates 10.1.3-0ubuntu0.4 upgradeable to 10.1.3-0ubuntu0.6
libgssapi-krb5-2:amd64/trusty-updates 1.12+dfsg-2ubuntu5.2 upgradeable to 1.12+dfsg-2ubuntu5.3
libgtk-3-0:amd64/trusty-updates 3.10.8-0ubuntu1.4 upgradeable to 3.10.8-0ubuntu1.6
libgtk-3-common:all/trusty-updates 3.10.8-0ubuntu1.4 upgradeable to 3.10.8-0ubuntu1.6
libgvc6:amd64/trusty-updates 2.36.0-0ubuntu3.1 upgradeable to 2.36.0-0ubuntu3.2
libgvpr2:amd64/trusty-updates 2.36.0-0ubuntu3.1 upgradeable to 2.36.0-0ubuntu3.2
libk5crypto3:amd64/trusty-updates 1.12+dfsg-2ubuntu5.2 upgradeable to 1.12+dfsg-2ubuntu5.3
libklibc:amd64/trusty-updates 2.0.3-0ubuntu1 upgradeable to 2.0.3-0ubuntu1.14.04.3
libkrb5-3:amd64/trusty-updates 1.12+dfsg-2ubuntu5.2 upgradeable to 1.12+dfsg-2ubuntu5.3
libkrb5support0:amd64/trusty-updates 1.12+dfsg-2ubuntu5.2 upgradeable to 1.12+dfsg-2ubuntu5.3
libmount1:amd64/trusty-updates 2.20.1-5.1ubuntu20.3 upgradeable to 2.20.1-5.1ubuntu20.9
libmtp-common:all/trusty-updates 1.1.6-20-g1b9f164-1ubuntu2 upgradeable to 1.1.6-20-g1b9f164-1ubuntu2.1
libmtp9:amd64/trusty-updates 1.1.6-20-g1b9f164-1ubuntu2 upgradeable to 1.1.6-20-g1b9f164-1ubuntu2.1
libnuma1:amd64/trusty-updates 2.0.9~rc5-1ubuntu2 upgradeable to 2.0.9~rc5-1ubuntu3.14.04.2
libpam-systemd:amd64/trusty-updates 204-5ubuntu20.9 upgradeable to 204-5ubuntu20.25
libparted0debian1:amd64/trusty-updates 2.3-19ubuntu1 upgradeable to 2.3-19ubuntu1.14.04.1
libpathplan4:amd64/trusty-updates 2.36.0-0ubuntu3.1 upgradeable to 2.36.0-0ubuntu3.2
libpci3:amd64/trusty-updates 1:3.2.1-1ubuntu5 upgradeable to 1:3.2.1-1ubuntu5.1
libpolkit-gobject-1-0:amd64/trusty-updates 0.105-4ubuntu2 upgradeable to 0.105-4ubuntu3.14.04.1
libprocps3:amd64/trusty-updates 1:3.3.9-1ubuntu2 upgradeable to 1:3.3.9-1ubuntu2.2
libpython3.4:amd64/trusty-security 3.4.0-2ubuntu1.1 upgradeable to 3.4.3-1ubuntu1~14.04.5
libpython3.4-minimal:amd64/trusty-security 3.4.0-2ubuntu1.1 upgradeable to 3.4.3-1ubuntu1~14.04.5
libpython3.4-stdlib:amd64/trusty-security 3.4.0-2ubuntu1.1 upgradeable to 3.4.3-1ubuntu1~14.04.5
libsnmp-base:all/trusty-updates 5.7.2~dfsg-8.1ubuntu3.1 upgradeable to 5.7.2~dfsg-8.1ubuntu3.2
libsnmp30:amd64/trusty-updates 5.7.2~dfsg-8.1ubuntu3.1 upgradeable to 5.7.2~dfsg-8.1ubuntu3.2
libss2:amd64/trusty-updates 1.42.9-3ubuntu1.2 upgradeable to 1.42.9-3ubuntu1.3
libsystemd-daemon0:amd64/trusty-updates 204-5ubuntu20.9 upgradeable to 204-5ubuntu20.25
libsystemd-login0:amd64/trusty-updates 204-5ubuntu20.9 upgradeable to 204-5ubuntu20.25
libudev1:amd64/trusty-updates 204-5ubuntu20.9 upgradeable to 204-5ubuntu20.25
libuuid1:amd64/trusty-updates 2.20.1-5.1ubuntu20.3 upgradeable to 2.20.1-5.1ubuntu20.9
libxrandr2:amd64/trusty-updates 2:1.4.2-1 upgradeable to 2:1.5.0-1~trusty1
logrotate:amd64/trusty-updates 3.8.7-1ubuntu1 upgradeable to 3.8.7-1ubuntu1.2
lsb-base:all/trusty-updates 4.1+Debian11ubuntu6 upgradeable to 4.1+Debian11ubuntu6.2
lsb-release:all/trusty-updates 4.1+Debian11ubuntu6 upgradeable to 4.1+Debian11ubuntu6.2
lshw:amd64/trusty-updates 02.16-2ubuntu1.3 upgradeable to 02.16-2ubuntu1.4
makedev:all/trusty-updates 2.3.1-93ubuntu1 upgradeable to 2.3.1-93ubuntu2~ubuntu14.04.1
mount:amd64/trusty-updates 2.20.1-5.1ubuntu20.3 upgradeable to 2.20.1-5.1ubuntu20.9
nfs-common:amd64/trusty-updates 1:1.2.8-6ubuntu1.1 upgradeable to 1:1.2.8-6ubuntu1.2
ntp:amd64/trusty-updates 1:4.2.6.p5+dfsg-3ubuntu2.14.04.11 upgradeable to 1:4.2.6.p5+dfsg-3ubuntu2.14.04.12
ntpdate:amd64/trusty-updates 1:4.2.6.p5+dfsg-3ubuntu2.14.04.11 upgradeable to 1:4.2.6.p5+dfsg-3ubuntu2.14.04.12
openssh-sftp-server:amd64/trusty-tools 1:6.6p1-2ubuntu2.8 upgradeable to 1:6.9p1-2~trusty1
parted:amd64/trusty-updates 2.3-19ubuntu1 upgradeable to 2.3-19ubuntu1.14.04.1
pciutils:amd64/trusty-updates 1:3.2.1-1ubuntu5 upgradeable to 1:3.2.1-1ubuntu5.1
procps:amd64/trusty-updates 1:3.3.9-1ubuntu2 upgradeable to 1:3.3.9-1ubuntu2.2
puppet:all/trusty-wikimedia 3.4.3-1ubuntu1.2 upgradeable to 3.8.5-2~bpo8trusty+2
puppet-common:all/trusty-wikimedia 3.4.3-1ubuntu1.2 upgradeable to 3.8.5-2~bpo8trusty+2
python-amqp:all/trusty-updates 1.3.3-1ubuntu1 upgradeable to 1.3.3-1ubuntu1.1
python-apt:amd64/trusty-updates 0.9.3.5ubuntu1 upgradeable to 0.9.3.5ubuntu2
python-apt-common:all/trusty-updates 0.9.3.5ubuntu1 upgradeable to 0.9.3.5ubuntu2
python-kombu:all/trusty-updates 3.0.7-1ubuntu1 upgradeable to 3.0.7-1ubuntu1.1
python-paramiko:all/trusty-wikimedia 1.10.1-1git1build1 upgradeable to 1.15.2-1
python-pkg-resources:all/trusty-updates 3.3-1ubuntu1 upgradeable to 3.3-1ubuntu2
python-setuptools:all/trusty-updates 3.3-1ubuntu1 upgradeable to 3.3-1ubuntu2
python-tz:all/trusty-updates 2012c-1build1 upgradeable to 2012c-1ubuntu0.1
python-urllib3:all/trusty-updates 1.7.1-1build1 upgradeable to 1.7.1-1ubuntu4
python-virtualenv:all/trusty-updates 1.11.4-1 upgradeable to 1.11.4-1ubuntu1
python3-apt:amd64/trusty-updates 0.9.3.5ubuntu1 upgradeable to 0.9.3.5ubuntu2
python3-distupgrade:all/trusty-updates 1:0.220.6 upgradeable to 1:0.220.9
python3-pkg-resources:all/trusty-updates 3.3-1ubuntu1 upgradeable to 3.3-1ubuntu2
python3-setuptools:all/trusty-updates 3.3-1ubuntu1 upgradeable to 3.3-1ubuntu2
python3-software-properties:all/trusty-updates 0.92.37.3 upgradeable to 0.92.37.8
python3-tz:all/trusty-updates 2012c-1build1 upgradeable to 2012c-1ubuntu0.1
python3-update-manager:all/trusty-updates 1:0.196.12 upgradeable to 1:0.196.24
python3-urllib3:all/trusty-updates 1.7.1-1ubuntu3 upgradeable to 1.7.1-1ubuntu4
python3.4:amd64/trusty-security 3.4.0-2ubuntu1.1 upgradeable to 3.4.3-1ubuntu1~14.04.5
python3.4-minimal:amd64/trusty-security 3.4.0-2ubuntu1.1 upgradeable to 3.4.3-1ubuntu1~14.04.5
resolvconf:all/trusty-updates 1.69ubuntu1.1 upgradeable to 1.69ubuntu1.3
rsyslog:amd64/trusty-updates 7.4.4-1ubuntu2.5 upgradeable to 7.4.4-1ubuntu2.7
snmp:amd64/trusty-updates 5.7.2~dfsg-8.1ubuntu3.1 upgradeable to 5.7.2~dfsg-8.1ubuntu3.2
software-properties-common:all/trusty-updates 0.92.37.3 upgradeable to 0.92.37.8
systemd-services:amd64/trusty-updates 204-5ubuntu20.9 upgradeable to 204-5ubuntu20.25
sysv-rc:all/trusty-updates 2.88dsf-41ubuntu6 upgradeable to 2.88dsf-41ubuntu6.3
sysvinit-utils:amd64/trusty-updates 2.88dsf-41ubuntu6 upgradeable to 2.88dsf-41ubuntu6.3
ttf-lyx:all/trusty-updates 2.0.6-1build1 upgradeable to 2.0.8.1-0ubuntu1
ubuntu-release-upgrader-core:all/trusty-updates 1:0.220.6 upgradeable to 1:0.220.9
udev:amd64/trusty-updates 204-5ubuntu20.9 upgradeable to 204-5ubuntu20.25
unattended-upgrades:all/trusty-updates 0.82.1ubuntu2.3 upgradeable to 0.82.1ubuntu2.5
usbutils:amd64/trusty-updates 1:007-2ubuntu1 upgradeable to 1:007-2ubuntu1.1
util-linux:amd64/trusty-updates 2.20.1-5.1ubuntu20.3 upgradeable to 2.20.1-5.1ubuntu20.9
uuid-runtime:amd64/trusty-updates 2.20.1-5.1ubuntu20.3 upgradeable to 2.20.1-5.1ubuntu20.9
x11-common:all/trusty-updates 1:7.7+1ubuntu8 upgradeable to 1:7.7+1ubuntu8.1

I: 128 upgradeable packages, 0 upgradeable packages by unatteneded-upgrades

Example output in debian stable stretch:

aborrero@stretch:~$ sudo bash report-pending-upgrades.sh 
I: updating package cache
I: 0 upgradeable packages, 0 upgradeable packages by unatteneded-upgrades

Updated script, which now shows upgradeable packages by repository

#!/bin/bash

if [ "$(id -u)" != "0" ] ; then
	echo "E: root required" >&2
	exit 1
fi

get_binary()
{
	BINARY=$(which $1)
	if [ ! -x "$BINARY" ] ; then
		echo "E: no $1 binary found" >&2
		exit 1
	fi
	echo $BINARY
}

set -e
APT_GET=$(get_binary apt-get)
APT_SHOW_VERSIONS=$(get_binary apt-show-versions)
UNATTENDED_UPGRADES=$(get_binary unattended-upgrades)
set +e

echo "I: $0 running on $(uname -n)"
echo "I: updating package cache"
$APT_GET update >/dev/null

APT_SHOW_VERSIONS_OUTPUT=$($APT_SHOW_VERSIONS | grep upgradeable | sort -t / -k 2)
n1=$(echo "$APT_SHOW_VERSIONS_OUTPUT" | grep -v ^$ | wc -l)

UNATTENDED_UPGRADES_OUTPUT=$($UNATTENDED_UPGRADES --dry-run -v -d | grep "Packages that will be upgraded" | awk -F':' '{print $2}' | grep -v ^[[:space:]]*$)
n2=$(echo "$UNATTENDED_UPGARDES_OUTPUT" | grep -v ^$ | wc -l)

if [ "$n1" != "0" ] ; then
	sources=$(echo "$APT_SHOW_VERSIONS_OUTPUT" | awk -F'/' '{print $2}' | awk -F' ' '{print $1}' | uniq)
	for src in $sources ; do
		src_output=$(echo "$APT_SHOW_VERSIONS_OUTPUT" | grep $src)
		n3=$(echo "$src_output" | wc -l)
		echo "I: upgradeable packages from ${src}: $n3"
		echo
		echo "$src_output" | sed -e 's/^/  /'
		echo
	done
fi

if [ "$n2" != "0" ] ; then
	echo "I: upgradeable packages by unattended-upgrades: $n2"
	echo
	echo "$UNATTENDED_UPGARDES_OUTPUT" | sed -e 's/^/  /'
	echo
fi
echo "I: $n1 upgradeable packages, $n2 upgradeable packages by unatteneded-upgrades"

Will probably put this on puppet somewhere