You are not logged in.
I have a backup script that run as root cron job:
export DISPLAY=:0
SHELL=/bin/bash
PATH=/bin:/usr/bin:/sbin:/usr/sbin
BACKUP_DIR="/run/media/leonidas/WD/backup"
LOG_FILE="/home/leonidas/backup.log"
rsync -rtvu --delete --log-file=$LOG_FILE /home/leonidas/Documents "$BACKUP_DIR"
notify-send --icon=gtk-add "Local Backup" "WD hard disk"
This is the cron job:
45 13 * * * /home/leonidas/backup.sh >/dev/null 2>&1
But the notify-send doesn't work. Could you provide any help please?
Last edited by leonidas (2017-02-12 13:58:21)
Offline
Please search before posting:
https://wiki.archlinux.org/index.php/De … rogramming
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
I have already test it.
I run from console:
sudo -u leonidas DISPLAY=:0 DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus notify-send 'Hello world!' 'This is an example notification.'
but it didn't work.
Please search before posting:
https://wiki.archlinux.org/index.php/De … rogramming
Offline
Is XAUTHORITY set?
Offline
It works as a regular user but not as root
Sanity check: is a notification server running, i.e. does notify-send work if you run it normally?
Offline
As root do you use the full line from post #3?
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Yes,
XAUTHORITY=/home/leonidas/.Xauthority
I also added it in my script with:
export XAUTHORITY=/home/leonidas/.Xauthority
but it still doesn't work
Is XAUTHORITY set?
Offline
Strange, that line it works! I thought the first time that it didn't.
It finally runs from root cron job.
So the line inside my script is:
sudo -u leonidas DISPLAY=:0 DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus notify-send "Local Backup" "WD hard disk"
As root do you use the full line from post #3?
Offline
I'm glad it works. Though I don't understand the reaction. This is the second time today someone exclaimed how strange it was that the command well documented in the wiki worked.
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Maybe I didn't notice the x_user or x_userid of the example...
Offline
Sorry for necropost. I was looking for a solution for the same problem and figured out how to run send-notify without sudo or su (which involves PAM and spams to journal):
# DISPLAY=:0 DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus setpriv --euid=1000 notify-send …
Last edited by dimich (2020-03-17 12:43:22)
Offline