In Ubuntu 14.04 esportare il display non ha funzionato per me. Di seguito è riportato uno script cron che sto utilizzando per arrestare una macchina virtuale quando lo stato della batteria di un laptop diventa troppo basso. L'impostazione della linea DBUS_SESSION_BUS_ADDRESS è la modifica che ha finalmente funzionato correttamente.
#!/bin/bash
# if virtual machine is running, monitor power consumption
if pgrep -x vmware-vmx; then
bat_path="/sys/class/power_supply/BAT0/"
if [ -e "$bat_path" ]; then
bat_status=$(cat $bat_path/status)
if [ "$bat_status" == "Discharging" ]; then
bat_current=$(cat $bat_path/capacity)
# halt vm if critical; notify if low
if [ "$bat_current" -lt 10 ]; then
/path/to/vm/shutdown/script
echo "$(date +%Y.%m.%d_%T)" >> "/home/user/Desktop/VM Halt Low Battery"
elif [ "$bat_current" -lt 15 ]; then
eval "export $(egrep -z DBUS_SESSION_BUS_ADDRESS /proc/$(pgrep -u $LOGNAME gnome-session)/environ)";
notify-send -i "/usr/share/icons/ubuntu-mono-light/status/24/battery-caution.svg" "Virtual machine will halt when battery falls below 10% charge."
fi
fi
fi
fi
exit 0
La linea in questione è qui:
eval "export $(egrep -z DBUS_SESSION_BUS_ADDRESS /proc/$(pgrep -u $LOGNAME gnome-session)/environ)";
ho trovato la soluzione qui: https://askubuntu.com/a/346580/255814
Solo l'aggiunta di "export DISPLAY =: 0.0" ha fatto il trucco per me.Detto questo, il cronjob è in esecuzione sotto il mio account utente. XAUTHORITY è probabilmente necessario quando viene eseguito da un account diverso da quello in cui il popup deve apparire. Grazie. – Ruben
Grazie, anche questo mi ha aiutato (non ho bisogno di usare "sudo") –
Anch'io. Potrei ridurre questo comando a '* * * * * export DISPLAY =: 0.0 && notify-send Hey" Come stai "? – TomTom