Skip to content

Instantly share code, notes, and snippets.

@relthyg
Created May 12, 2019 08:57
Show Gist options
  • Save relthyg/729c09e100b465bd149fc4c2902b3f59 to your computer and use it in GitHub Desktop.
Save relthyg/729c09e100b465bd149fc4c2902b3f59 to your computer and use it in GitHub Desktop.
How to get notified about available apt updates in your shell
// /etc/apt/apt.conf.d/60aptchecker
// runs aptchecker after dpkg (e.g. apt upgrade)
DPkg::Post-Invoke {'/opt/bin/aptchecker';};

This is a simple solution to get notified of the number of available package updates in your shell. It runs apt update regularly in the background and saves the line XX packages can be upgraded to a file if any updates are available. If not, the file is deleted. When you open a terminal window, the existance of this file is checked and if positive, its content is echoed.

  • You may want to have anacron installed.
  • Copy aptchecker and 60aptchecker to their according directories mentioned in the comments.
  • Add a symlink for /opt/bin/aptchecker to /etc/cron.daily: ln -s /opt/bin/aptchecker /etc/cron.daily/
  • Add the line from bashrc-snippet to your .bashrc (or whatever shell you may use).
#!/bin/sh
# /opt/bin/aptchecker
# Symlink me in /etc/cron.hourly or /etc/cron.daily
LISTFILE=/var/opt/available-updates.txt
apt update 2>/dev/null | grep "can be upgraded" > $LISTFILE || rm -f $LISTFILE
# ...
[[ -f /var/opt/available-updates.txt ]] && cat /var/opt/available-updates.txt
# ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment