[Workaround] Can't Display Notifications as root

About writing shell scripts and making the most of your shell
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Locked
ajgringo619

[Workaround] Can't Display Notifications as root

Post by ajgringo619 »

I have just completed the transition from XFCE to Cinnamon. I'm working on converting some of my scripts and have ran into a problem I can't seem to solve. I have a backup script that displays notifications when it starts and stops, as well as when it needs me to plug in my portable USB drive. When using XFCE, the following worked:

Root crontab

Code: Select all

SHELL=/bin/bash

DISPLAY=":0.0"
XAUTHORITY="/home/me/.Xauthority"
XDG_RUNTIME_DIR="/run/user/1000"

00 10 * * * /usr/local/sbin/rsync_backup >> /var/log/rsync_backup.log
00 21 * * * /usr/local/sbin/clonezilla_backup > /dev/null
Notification (from rsync_backup)

Code: Select all

zenity --notification --window-icon="info" --text="Daily backup started - `date +%Y-%m-%d` @ `date +%H:%M`"
Now, using Cinnamon, none of my zenity notifications work. I even tried going back to notify-send, but that doesn't work either. The strange thing is that it's only notifications; when I use something like zenity --warning --text="This is a test" from root's crontab (or the terminal, for that matter), the message window works as expected. When I try to run the notification command from the terminal, I get this error:

Code: Select all

zenity --notification --text="Testing"

** (zenity:24500): WARNING **: 15:44:58.055: Error showing notification: GDBus.Error:org.freedesktop.DBus.Error.ServiceUnknown: The name org.freedesktop.Notifications was not provided by any .service files
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 2 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
ajgringo619

Re: Can't Display Notifications as root

Post by ajgringo619 »

OK - adding export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus to my root crontab makes notify-send work, but zenity (notifications only) still does not. I have to run them like this:

Code: Select all

su me -c '/usr/bin/notify-send "Daily backup ended - `date +%Y-%m-%d` @ `date +%H:%M:%S`"'
User avatar
MrEen
Level 23
Level 23
Posts: 18345
Joined: Mon Jun 12, 2017 8:39 pm

Re: [Workaround] Can't Display Notifications as root

Post by MrEen »

ajgringo619 wrote: Sat Jul 06, 2019 6:48 pm

Code: Select all

zenity --notification --text="Testing"

** (zenity:24500): WARNING **: 15:44:58.055: Error showing notification: GDBus.Error:org.freedesktop.DBus.Error.ServiceUnknown: The name org.freedesktop.Notifications was not provided by any .service files
I'm still on 18.3 Xfce. The above worked perfectly for me. And by perfectly I mean I didn't even get the usual "Gtk-Message: GtkDialog mapped without a transient parent. This is discouraged." warning.

Sorry I can't help any more than that. (Like that was of any help whatsoever.)

EDIT: I just went into Menu > Settings > Notifications > Applications tab and unchecked Zenity notification then ran the above again. Still no warning, but also no notification. Maybe Cinnamon has a similar setting?
ajgringo619

Re: [Workaround] Can't Display Notifications as root

Post by ajgringo619 »

Cinnamon doesn't have a way, at least through the System Settings, to turn off individual application notifications; I'm going to really miss the XFCE Notification plug-in! :cry: I'm going to have to do some research on how exactly Cinnamon handles notifications.
Locked

Return to “Scripts & Bash”