1

I am using Kubuntu 20.04 Focal (KDE Plasma v5.18.5, KDE Frameworks v5.68.0, Qt v5.12.8) and I have a bunch of Bash scripts that are expected to post some notifications, to the user and this is the step I am currently having unresolved issues with. To post notifications I am using notify-send (from libnotify-bin package) and kdialog (from kdialog package). The minimal, complete and verifiable example for my case can look like this (say, it's /tmp/test.sh, executable file):

#!/bin/bash

notify-send "notify-send test"
kdialog --passivepopup 'kdialog test' 5

When you run this script manually, it works just fine and produces what you expect - shows the notification that appears on your destkop. In my case it's expected to show up in bottom-left corner of the screen as I do have vertical panel on the left edge:

Expected results

However when I try to run my scripts from a cron job, with crontab entry like this:

* * * * * DISPLAY=:0 /tmp/test.sh

notify-send fails completely (shows nothing) and kdialog shows something oddly themed and misplaced (in top-left part of the screen):

kdialog popup

The cron job is running on behalf of my user and I am logged during the tests. When checking syslog I see:

Sep 10 20:05:01 HOST CRON[159928]: (USER) CMD (DISPLAY=:0 /tmp/test.sh)
Sep 10 20:05:15 HOST org.freedesktop.Notifications[159641]: org.kde.knotifications: WaitForName: Service was not registered within timeout
Sep 10 20:05:15 HOST dbus-daemon[76746]: [session uid=1000 pid=76744] Activated service 'org.freedesktop.Notifications' failed: Process org.freedesktop.Notifications exited with status 1
Sep 10 20:05:15 HOST dbus-daemon[76746]: [session uid=1000 pid=76744] Activating service name='org.freedesktop.Notifications' requested by ':1.497' (uid=1000 pid=159930 comm="notify-send notify-send test " label="unconfined")

I was searching for org.kde.knotifications: WaitForName: Service was not registered within timeout but failed to find any explanation what this is really caused by. I suspect that cron job environment is missing something (i.e. say env var?) that is otherwise present when launched from interactive shell, but I somehow stuck and not sure what to check next. So, ancient, posts suggested turning off panel auto-hide (I am no using auto-hide feature) or ensuring I did not mute notifications in tray (not my case either). I definitely lacks some knowledge here, so my question is - what is really preventing notification from showing up as expected? I understand that running cron job is not an equivalent of user's manual launch, yet I failed to figure out what is really the vital difference here that I should artificially provide. What shall I peek next in my finding culprit quest? I am simply out of ideas at the moment, and nothing I found during my search crusade pushed mu any step forward right now.

I'd really apreciate any hints or thoughts about that or what to peek/read/investigate next as I am currently out of ideas.

2

I've seen other people been successful setting DBUS_SESSION_BUS_ADDRESS or XDG_RUNTIME_DIR.

I had a try locally and these works fine here.

* * * * * DISPLAY=:0 DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$(id -u)/bus /tmp/test.sh

or

* * * * * DISPLAY=:0 XDG_RUNTIME_DIR=/run/user/$(id -u) /tmp/test.sh
1
  • Funny thing is that my real scripts are checking and setting DBUS_SESSION_BUS_ADDRESS but apparently I got this implemented incorrectly. At least I know where to investigate further. Thanks. – Marcin Orlowski Sep 11 '20 at 6:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.