Introduction
Do you ever want to get a notification with the number of updates required when logging into XFCE in debian/ubuntu like systems ?
There is a simple python script that can do just that.
It uses notify-send
command and paired with the magic command that returns the update count, we get the next python script:
#!/usr/bin/env python3
import os
import subprocess
# Run the apt-get command and grep the output
command = 'apt-get --simulate upgrade | grep "upgraded.*newly installed"'
output = subprocess.getoutput(command)
# If there's output, send it as a notification, otherwise send a default message
if output:
os.system(f'notify-send "Upgrade Check" "{output}"')
else:
os.system('notify-send "Upgrade Check" "No upgrades available or no packages to be installed."')
# Check if the file /var/run/reboot-required exists
reboot_file = '/var/run/reboot-required'
if os.path.exists(reboot_file):
os.system('notify-send "System Update" "Reboot is required to complete updates."')
All you need is to make it executable:
chmod +x /path/to/script/login-update-notifier.py
And also add it as a command to run at login.
In XFCE you can use Applications Menu > Settings > Session and Startup and add the script here.
If everything it’s ok, then the notification will look like:
Documentation and links:
- List the number of packages to be upgraded like apt - https://unix.stackexchange.com/questions/774304/apt-get-update-does-not-list-the-number-of-packages-to-be-upgraded-like-apt
- How to find out if my Ubuntu/Debian Linux server needs a reboot - https://www.cyberciti.biz/faq/how-to-find-out-if-my-ubuntudebian-linux-server-needs-a-reboot/