I'm trying to make a simple weekly Anacron job that backs up my computer if I click yes on the dialog. The script I wrote works fine if run manually, but when Anacron runs it, nothing happens and I see Gtk-WARNING **: cannot open display
in the logs. Apparently the script is run at a stage where graphical operations cannot be run. Is there any way to get this dialog to open from an Anacron job?
Code:
#!/bin/sh
# Backs up the local filesystem on the external HDD
sleep 60
DISPLAY=:0.0
zenity --question --text "Do you want to backup? Be sure to turn on the HDD."
if [ $? -ne 0 ]
then exit 1
fi
*Do backup stuff here*
Error:
(zenity:2351): Gtk-WARNING **: cannot open display:
run-parts: /etc/cron.daily/backup-on-external exited with return code 1
DISPLAY
is that (ana)cron jobs are supposed to be able to run even if nobody is logged in. Relying on someone being logged in is not a good idea for something that should be automatic like a backup script (a better design would be to perform the backup if the right media is in place, and rely on the usual failure notification (through e-mail) to alert the user if the right media was not in place and the backup could not be made). – Gilles 'SO- stop being evil' Nov 22 '10 at 19:45XAUTHORITY
as well. The default, used if the variable is unset, is~/.Xauthority
. Some systems (e.g. Ubuntu) use a different file, and it can be a little hard to find out. If that's the issue, see http://superuser.com/questions/190801/linux-wmctrl-cannot-open-display-when-session-initiated-via-sshscreen/190878#190878 and http://unix.stackexchange.com/questions/1596/as-root-can-i-launch-a-graphical-program-on-another-users-desktop/1600#1600 . – Gilles 'SO- stop being evil' Nov 23 '10 at 19:07