Simple Update Notifier

If you have a debian-based distro that is not Ubuntu or Mint (both of which I view as Linux for Apple for Microsoft GUI babies) you may or may not have an update checker task bar applet that lets you know updates are available. Below is a simple script that will do just that.

#!/usr/bin/python
import os
import commands
import re

packages = -1
security = -1

command = commands.getoutput('/usr/lib/update-notifier/apt-check --human-readable')
lines = command.split('\n')

for line in lines:
    match = re.match('\d+ packages can be updated.', line, re.M|re.I)
    if match:
        parts = line.split(' ')
        packages = int(parts[0])
    match = re.match('\d+ updates are security updates.', line, re.M|re.I)
    if match:
        parts = line.split(' ')
        security = int(parts[0])

updates = (packages > 0) or (security > 0)

if  updates:
    os.system("/usr/bin/yad --notification --no-buttons --text=\"package updates: " + str(packages) + "\nsecurity updates: " + str(security) + "\"")

Here’s how it will show in the task bar (I use tint2):

screenshot-20151130213546_253x48

 

 

Then you simply run:

sudo apt-get -y upgrade

Here’s a wrapper script that you can throw into your crontab:

#!/bin/sh

LOCK=/tmp/update_checker.lock ; export LOCK

if [ -f $LOCK ]; then
  echo "$0 already running; exiting ..."
  exit 1
fi

touch $LOCK

$HOME/bin/update_check.py >> $LOCK 2>&1

rm $LOCK

Execute the above script every 4 hours (or however frequent you want):

* */4 * * * DISPLAY=:0 /home/cygnus/bin/update_checker.sh > /dev/null 2>&1

Leave a Reply