I'm working on a bash script which requires root privileges, but which I'd like to give the ability to notify a non-root user of certain alerts via notify-send in GNOME (or any other desktop shell supporting that command). As expected, simply invoking notify-send from a root shell doesn't display a notification on the non-root user's desktop.

I've tried to invoke the command via:

su -c "notify-send 'my message'" -s /bin/sh someuser

(as well as using /bin/bash, /usr/zsh), but neither of these has had any effect.

How can I invoke notify-send from a root shell so that it shows a notification on a (specified) non-root user's desktop?


You have to do something like this:

DISPLAY=:0.0 su $USER -c "/usr/bin/notify-send 'my message'"

The above is how I have done in the past with cron jobs that are run as root. Of course you need to specify an actual user in the $USER variable.

| improve this answer | |
  • 2
    This approach doesn't seem to work under GNOME 3.22.1 with notify-send 0.7.7 running on Arch Linux (kernel 4.8.6). Can you confirm whether, in past cases, it's worked with applications which affect a GUI desktop environment? – Jules Nov 13 '16 at 9:13
  • I use this in a cron job under Debian with Xfce as desktop environment. I have no machine with Gnome to test on unfortunately. – maulinglawns Nov 13 '16 at 9:42

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