You are not logged in.
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
$ 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
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
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
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
Nope This is the point...
Offline
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