env
when invoked from a script run by cron
, only had the following variables set in my box.
SHELL=/bin/sh USER=clement PATH=/usr/bin:/bin PWD=/home/clement HOME=/home/clement SHLVL=2 LOGNAME=clement _=/usr/bin/env
and so grep
in
$(env | grep DBUS_SESSION_BUS_ADDRESS | sed 's/DBUS_SESSION_BUS_ADDRESS=//')
didn't give any output. The following should work.
#!/bin/bash
PID=$(pgrep gnome-session)
dbus=$(grep -z DBUS_SESSION_BUS_ADDRESS /proc/$PID/environ|cut -d= -f2-)
export DBUS_SESSION_BUS_ADDRESS=$dbus
notify-send -u critical "Blah" "Blubb"