Problems posting notifications from bash script started from cron (KDE)

Spread the love
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  

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 in bottom-left corner of the screen):

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 in top-left part of the screen (I do have vertical panel on my left edge of the screen):

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 equivalet of user’s manual launch, yet I failed to figure out what is really the vital difference here that I should artifically 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 crusate pushed mu any step forward right now. I’d really apreciate any hints or thoughts about that.

X ITM Cloud News

Marisa

Leave a Reply

Next Post

E: The package packettracer needs to be reinstalled, but I can't find an archive for it

Fri Sep 11 , 2020
Spread the love          I have tried all ways out to resolve this problem but every time it shows the same thing again. X ITM Cloud News
X- ITM

Cloud Computing – Consultancy – Development – Hosting – APIs – Legacy Systems

X-ITM Technology helps our customers across the entire enterprise technology stack with differentiated industry solutions. We modernize IT, optimize data architectures, and make everything secure, scalable and orchestrated across public, private and hybrid clouds.

This image has an empty alt attribute; its file name is x-itmdc.jpg

The enterprise technology stack includes ITO; Cloud and Security Services; Applications and Industry IP; Data, Analytics and Engineering Services; and Advisory.

Watch an animation of  X-ITM‘s Enterprise Technology Stack

We combine years of experience running mission-critical systems with the latest digital innovations to deliver better business outcomes and new levels of performance, competitiveness and experiences for our customers and their stakeholders.

X-ITM invests in three key drivers of growth: People, Customers and Operational Execution.

The company’s global scale, talent and innovation platforms serve 6,000 private and public-sector clients in 70 countries.

X-ITM’s extensive partner network helps drive collaboration and leverage technology independence. The company has established more than 200 industry-leading global Partner Network relationships, including 15 strategic partners: Amazon Web Services, AT&T, Dell Technologies, Google Cloud, HCL, HP, HPE, IBM, Micro Focus, Microsoft, Oracle, PwC, SAP, ServiceNow and VMware

.

X ITM