You are not logged in.

#1 2011-06-29 16:02:26

Alie Alexandross
Member
Registered: 2011-05-03
Posts: 12

Running notify-send via cron

I've written a script, that monitors battery state and shuts down netbook when power is low to prevent hot power off. I've tested the script before running it in cron - everything works as it must: notification pops up, system shuts down. But when I'm trying to run it from cron - everything ok expect notify-send command.

Config scripts:

# crontab -e

# root crontab
# DO NOT EDIT THIS FILE MANUALLY! USE crontab -e INSTEAD

# man 1 crontab for acceptable formats:
#    <minute> <hour> <day> <month> <dow> <tags and command>
#    <@freq> <tags and command>
DISPLAY=:0.0
SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
# SYSTEM DAILY/WEEKLY/... FOLDERS
@hourly         ID=sys-hourly   /usr/sbin/run-cron /etc/cron.hourly
@daily          ID=sys-daily    /usr/sbin/run-cron /etc/cron.daily
@weekly         ID=sys-weekly   /usr/sbin/run-cron /etc/cron.weekly
@monthly        ID=sys-monthly  /usr/sbin/run-cron /etc/cron.monthly
* * * * * /etc/cron.hourly/powersave
$ cat /etc/cron.hourly/powersave

PasteBin

$ cat /etc/X11/xorg.conf | head -n 6
Section "ServerLayout"
        Identifier     "X.org Configured"
        Screen    0    "Screen0" 0 0
        InputDevice    "LG_Touchpad" "CorePointer"
        InputDevice    "LG_Keyboard" "CoreKeyboard"
EndSection
$ echo $DISPLAY

I thought that running one more external script will solve the problem, but it didn't work.
Tried also this command in cron:

* * * * * DISPLAY=:0.0 /etc/cron.hourly/powersave

But also without result.

Anyone found a solution to this problem?

Offline

#2 2011-06-30 07:13:14

Wey
Member
Registered: 2011-04-22
Posts: 217

Re: Running notify-send via cron

Hello Alie Alexandross,
have a look at Cdh's last post in https://bbs.archlinux.org/viewtopic.php?id=120501. It basically boils down to using sudo -u $USER notify-send ... and eventually exporting XAUTHORITY.

Offline

#3 2011-07-01 16:37:40

Alie Alexandross
Member
Registered: 2011-05-03
Posts: 12

Re: Running notify-send via cron

Thanks for an answer. I've read the topic you gave me and tried solutions posted there. Still no changes. Script runs every minute, as noticed in cron.log, dmesg shows no errors. Tried running cron from user and root.

Offline

#4 2011-07-01 17:39:09

Wey
Member
Registered: 2011-04-22
Posts: 217

Re: Running notify-send via cron

Does the following work as expected if executed as root from a tty, replacing alie with the user logged in on x?

DISPLAY=:0 sudo -u alie notify-send "test"

Offline

#5 2011-07-01 21:07:47

Alie Alexandross
Member
Registered: 2011-05-03
Posts: 12

Re: Running notify-send via cron

Nope sad This is the point...

Offline

#6 2011-07-02 02:31:41

pnutzh4x0r
Member
Registered: 2009-08-11
Posts: 24

Re: Running notify-send via cron

You may also need to have the DBUS_SESSION_BUS_ADDRESS environment variable set.  I have a script that does something like this:

PIDS=$(pgrep urxvtd)

for p in $PIDS; do
    dbus=$(grep -z DBUS_SESSION_BUS_ADDRESS /proc/$p/environ | sed 's/DBUS_SESSION_BUS_ADDRESS=//')
    user=$(grep -z USER /proc/$p/environ | sed 's/USER=//')
    dply=$(grep -z DISPLAY /proc/$p/environ | sed 's/DISPLAY=//')

    sudo -u $user sh -c "DBUS_SESSION_BUS_ADDRESS=\"$dbus\" DISPLAY=\"$dply\" /usr/bin/notify-send -i \"$ICON\" \"$TITLE\" \"$BODY\""
done

I chose urxvtd, b/c it's guaranteed to be running... but you can choose another progam.

Last edited by pnutzh4x0r (2011-07-02 02:32:16)

Offline

Board footer

Powered by FluxBB