Article 5BX10 How to use "slackpkg check-updates" in a script

How to use "slackpkg check-updates" in a script

by
gegechris99
from LinuxQuestions.org on (#5BX10)
drgibbon asked in thread "Requests for -current (14.2-->15.0)" (see post here)

Quote:
Question (possibly a request) for `slackpkg check-updates`, the man page says:
Quote:
Verify if there is any update to ChangeLog.txt. This is good to be used from cron to alert the sysadmin about updates.
But the return value always seems to be zero (whether there are updates or not). How is it meant to be used in a script?
I want to provide a "workaround" solution here and not pollute the above-mentioned thread.

For the avoidance of doubt, we'll discuss the stock slackpkg, not the slackpkg+ extension. Checking updates with slackpkg+ is covered in this post.

If there is no update, you'll get:
Code:$ slackpkg check-updates

No updated packages since last check.If there is an update:
Code:$ slackpkg check-updates

Updated packages are available since last check.We can create script check_slackware_update.sh to send a notification when there is an update:
Code:#!/bin/bash
/usr/bin/mkdir -p ~/.slackpkg
/usr/sbin/slackpkg check-updates | /usr/bin/sed -n '/available/ p' > ~/.slackpkg/updated-repo.txt
username=$(/usr/bin/whoami)
pid=$(pgrep -u $username kded5)
dbus=$(grep -z DBUS_SESSION_BUS_ADDRESS /proc/$pid/environ | sed 's/DBUS_SESSION_BUS_ADDRESS=//')
export DBUS_SESSION_BUS_ADDRESS=$dbus
[ -s ~/.slackpkg/updated-repo.txt ] && /usr/bin/notify-send -i dialog-warning "[ S L A C K P K G ]" "Available updates"The above script works only on Plasma 5 as I use process kded5 to retrieve environment variable DBUS_SESSION_BUS_ADDRESS in the cron context.

The script could then be added to the user crontab (not the root one):
Code:$ crontab -l
SHELL=/bin/bash

# Check update of Slackware packages
0 * * * * sh ~/check_slackware_update.shBash experts will no doubt clean up my script. You're welcome.

Also, to get DBUS_SESSION_BUS_ADDRESS in cron in any DE, I have only this:
Code:DBUS_SESSION_BUS_ADDRESS=$(ps -u chris e | grep -Eo 'dbus-daemon.*ADDRESS=unix:abstract=/tmp/dbus-[A-Za-z0-9]{10}' | tail -c35)What is the cleanest way to get DBUS_SESSION_BUS_ADDRESS in cron environment?latest?d=yIl2AUoC8zA latest?i=ixUwCO77prY:t4Upk72Dy5o:F7zBnMy latest?i=ixUwCO77prY:t4Upk72Dy5o:V_sGLiP latest?d=qj6IDK7rITs latest?i=ixUwCO77prY:t4Upk72Dy5o:gIN9vFwixUwCO77prY
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments