Create system-notifications.sh 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
#
# SPDX-FileCopyrightText: 2017-2024 Joas Schilling <coding@schilljs.com>
# SPDX-License-Identifier: MIT
ADMIN="admin"
OCC_PATH="/var/www/nextcloud/occ"
PACKAGES=$(/usr/lib/update-notifier/apt-check -p 2>&1)
NUM_PACKAGES=$(echo "$PACKAGES" | wc -l)
if [ "$PACKAGES" != "" ]; then
UPDATE_MESSAGE=$(echo "$PACKAGES" | sed -r ':a;N;$!ba;s/\n/, /g')
NOTIFICATION_ID=$($OCC_PATH notification:generate $ADMIN \
"{packages} require to be updated" --short-parameters "{\"packages\":{\"type\":\"highlight\",\"id\":\"count\",\"name\":\"$NUM_PACKAGES packages\"}}" \
-l "Packages to update: {list}" --long-parameters "{\"list\":{\"type\":\"highlight\",\"id\":\"list\",\"name\":\"$UPDATE_MESSAGE\"}}" \
--object-type='updates' --object-id='apt' --output-id-only)
echo "$NOTIFICATION_ID" > apt-notification-id.txt
elif [ -f /var/run/reboot-required ]; then
NOTIFICATION_ID=$($OCC_PATH notification:generate $ADMIN "System requires a reboot"
echo "$NOTIFICATION_ID" > apt-notification-id.txt
else
NOTIFICATION_ID=$(cat apt-notification-id.txt)
$OCC_PATH notification:delete $ADMIN $NOTIFICATION_ID
fi
2. Add the script to the cronjob crontab -u www-data -e:
0 10 * * * /path/to/file/system-notifications.sh
[Update] Raspbian and other systems
If your operating system does not support apt-check, you can also try to replace the line:
This at least made it work on my Raspberry Pi which runs Raspbian.
Nextcloud 29 or older
Few of the options used above are only available in Nextcloud 30 and newer. So here is a version that works on older versions. It comes with the disadvantage of not replacing and removing the old notifications when a new one is triggered:
#!/usr/bin/env bash
#
# SPDX-FileCopyrightText: 2017 Joas Schilling <coding@schilljs.com>
# SPDX-License-Identifier: MIT
ADMIN="admin"
OCC_PATH="/var/www/nextcloud/occ"
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"
fi
Thanks a lot! I’d love to have that feature.
But i cant seem to get it working.
I installed admin-notifications,
the cron task (space at the end of the line, empty line at eof),
and changed the path and admin vars in the script.
I can see that cron was running in syslog and i can manually set a notification
(sudo -u www-data php /path/to/nextcloud/occ notification:generate admin “test”).
And i checked that apt-check works for www-data.
Nonetheless they wont show up
Any idea what i might be missing?
System is Nextcloud 12.0.3; Ubuntu 14.04; php 7.1.9
If i mark it as executable i get “not authorized” on line 15
($OCC_PATH notification:generate $ADMIN “$NUM_PACKAGES packages require to be updated” -l “$UPDATE_MESSAGE”).
But as i know it shouldnt be necessary to mark it as such?!
(due to #! )
ps.: owner of the file is www-data as i use apache
pss: copypasted the wrong line, now its right
No, you have to added it. I correct this issue and added check if user is the same as OCC owner. Also will create Log line with status. Works good under debian and ubuntu.