You are not logged in.

#1 2017-02-12 12:08:01

leonidas
Member
From: Greece
Registered: 2012-08-31
Posts: 49
Website

[SOLVED] Cannot run notify-send from cron job

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

#2 2017-02-12 12:11:06

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,570
Website

Re: [SOLVED] Cannot run notify-send from cron job


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Online

#3 2017-02-12 12:38:21

leonidas
Member
From: Greece
Registered: 2012-08-31
Posts: 49
Website

Re: [SOLVED] Cannot run notify-send from cron job

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.

Trilby wrote:

Offline

#4 2017-02-12 12:43:24

ayekat
Member
Registered: 2011-01-17
Posts: 1,591

Re: [SOLVED] Cannot run notify-send from cron job

Sanity check: is a notification server running, i.e. does notify-send work if you run it normally?


pkgshackscfgblag

Offline

#5 2017-02-12 13:09:27

brebs
Member
Registered: 2007-04-03
Posts: 3,742

Re: [SOLVED] Cannot run notify-send from cron job

Is XAUTHORITY set?

Offline

#6 2017-02-12 13:27:46

leonidas
Member
From: Greece
Registered: 2012-08-31
Posts: 49
Website

Re: [SOLVED] Cannot run notify-send from cron job

It works as a regular user but not as root

ayekat wrote:

Sanity check: is a notification server running, i.e. does notify-send work if you run it normally?

Offline

#7 2017-02-12 13:39:48

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,570
Website

Re: [SOLVED] Cannot run notify-send from cron job

As root do you use the full line from post #3?


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Online

#8 2017-02-12 13:40:17

leonidas
Member
From: Greece
Registered: 2012-08-31
Posts: 49
Website

Re: [SOLVED] Cannot run notify-send from cron job

Yes,

XAUTHORITY=/home/leonidas/.Xauthority

I also added it in my script with:

export XAUTHORITY=/home/leonidas/.Xauthority

but it still doesn't work

brebs wrote:

Is XAUTHORITY set?

Offline

#9 2017-02-12 13:57:47

leonidas
Member
From: Greece
Registered: 2012-08-31
Posts: 49
Website

Re: [SOLVED] Cannot run notify-send from cron job

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"
Trilby wrote:

As root do you use the full line from post #3?

Offline

#10 2017-02-12 14:20:18

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,570
Website

Re: [SOLVED] Cannot run notify-send from cron job

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

Online

#11 2017-02-17 05:48:57

leonidas
Member
From: Greece
Registered: 2012-08-31
Posts: 49
Website

Re: [SOLVED] Cannot run notify-send from cron job

Maybe I didn't notice the x_user or x_userid of the example...

Offline

#12 2020-03-17 12:41:46

dimich
Member
From: Kharkiv, Ukraine
Registered: 2009-11-03
Posts: 243

Re: [SOLVED] Cannot run notify-send from cron job

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

Board footer

Powered by FluxBB