Joas Schilling

Nextcloud Software Engineer

Public key: 31B0 B117 C3A8 2811 6B83 345C 7076 EA97 51AA CDDA

Howto get notifications for system updates
March 17, 2017

Keep your server up to date and receive a notification in your Nextcloud when php, apache, etc. need an update with this little script.

Update 21/Apr/17: Also works on Raspbian and others now.

Notifications for system updates

  1. Install the admin_notifications app
  2. Create with the following content on your system, and make sure to adjust the path to your nextcloud /var/www/nextcloud/occ as well as your admin account name:

     #!/usr/bin/env bash
     # @license MIT
     # @copyright 2017 Joas Schilling
     PACKAGES=$(/usr/lib/update-notifier/apt-check -p 2>&1)
     NUM_PACKAGES=$(echo "$PACKAGES" | wc -l)
     if [ "$PACKAGES" != "" ]; then
     	UPDATE_MESSAGE=$(echo "Packages to update: $PACKAGES" | sed -r ':a;N;$!ba;s/\n/, /g')
     	$OCC_PATH notification:generate $ADMIN "$NUM_PACKAGES packages require to be updated" -l "$UPDATE_MESSAGE"
     elif [ -f /var/run/reboot-required ]; then
     	$OCC_PATH notification:generate $ADMIN "System requires a reboot"
  3. Add the script to the cronjob crontab -u www-data -e

     0 10 * * * /path/to/file/

Leave comments in the Nextcloud forum.

[Update] Raspbian and other systems

If your operating system does not support apt-check, you can also try to replace the line:

PACKAGES=$(/usr/lib/update-notifier/apt-check -p 2>&1)


PACKAGES=$(apt-get -s dist-upgrade | awk '/^Inst/ { print $2 }' 2>&1)

This at least made it work on my Raspberry Pi which runs Raspbian.