Skip to content

Commit bd8e9c7

Browse files
committed
Update ubuntu_update_check.sh
* /usr/lib/update-notifier/apt-check was not returning a count of upgradeable packages on various machines even though you could see packages available for update via `apt-get update` * Replace with `apt list --upgradeable` and parse out the count of upgradeable security and non-security package updates available
1 parent ec0eefd commit bd8e9c7

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

ubuntu_updates_check.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@
2323
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2424
# THE SOFTWARE.
2525

26-
OUTPUT=$(/usr/lib/update-notifier/apt-check 2>&1)
26+
OUTPUT=$(apt list --upgradable 2>/dev/null)
2727

2828
if [ $? -ne 0 ]; then
2929
echo "Failed to retrieve a number of pending updates"
3030
exit 100
3131
fi
3232

33-
PENDING_OTHER=$(echo "${OUTPUT}" | cut -d ";" -f 1)
34-
PENDING_SECURITY=$(echo "${OUTPUT}" | cut -d ";" -f 2)
33+
PENDING_OTHER=$(echo "${OUTPUT}" | grep -v "Listing..." | grep -v -P "(,|/)$(lsb_release -cs)-security" | wc -l)
34+
PENDING_SECURITY=$(echo "${OUTPUT}" | grep -v "Listing..." | grep -P "(,|/)$(lsb_release -cs)-security" | wc -l)
3535
REBOOT_REQUIRED="no"
3636

3737
if [ -f "/var/run/reboot-required" ]; then
@@ -51,4 +51,4 @@ echo "metric pending_other uint32 ${PENDING_OTHER}"
5151
echo "metric reboot_required string ${REBOOT_REQUIRED}"
5252
echo "metric upgradable_packages string ${UPGRADABLE_PACKAGES}"
5353

54-
exit 0
54+
exit 0

0 commit comments

Comments
 (0)