EanderAlx.org

Linux, Virtualization and whatever I find interesting ...

User Tools


Site Tools



notify-send from cron

tested with Arch x64 and Gnome 2.3

  • If you send an notfiy-send from a cron and use gnome then you normally get an error message.

libnotify-Message: Unable to get session bus: /usr/bin/dbus-launch terminated abnormally with the following error: Autolaunch error: X11 initialization failed.
  • The right User Environment is missing in crontab.

Solution

  • You have to save your dbus-session ID and have to know the screen to which the message is send.
  • e.g.:
echo `set | grep DBUS_SESSION_BUS_ADDRESS | cut -d "=" -f2-4` > /tmp/dbus_session_hostname
  • or (only with root privileges):
sudo grep -z DBUS_SESSION_BUS_ADDRESS /proc/`/bin/pidof gnome-session`/environ | cut  -d "=" -f2-4 > /tmp/dbus_session_id
CONTENT=`cat /tmp/dbus_session_id`
echo $CONTENT > /tmp/dbus_session_id
  • Now you can give this informations to notify-send and send the message to the correct user environment
  • e.g.:
sudo -u username DISPLAY=:0.0 DBUS_SESSION_BUS_ADDRESS=`cat /tmp/dbus_session_hostname` /usr/bin/notify-send Inventur "daily inventur complete"
  • With “sudo -u” you can send the message from root crontab to a special user else it will send to the owner of the crontab.
linux/notify_send_cron.txt · Last modified: 23.03.2013 18:39 by eanderalx