Hi,
I try to use cron to run a GUI program. I am halfway there and have some problems. The true nature of my problems actually have nothing to do with cron, but with X session.
My script "run_gui.sh" will export some environment variables including DISPLAY and XAUTHORITY and run a JAVA GUI program. To test if run.sh can be run by cron, I typed this command:
env -i /fs/path_to/run_gui.sh
(I find if the command above works, then cron will be able to run it; if not, cron of course cannot run it either.) This command sometimes work and sometimes don't. Within run_gui.sh:
export XAUTHORITY=...
export DISPLAY=host-machine-name:0.1
Every time when I log in, I need to use this two commands:
env | grep XAUTHORITY
env | grep DISPLAY
to find out the two variable values, then edit run_gui.sh:
export XAUTHORITY=the_value_i_found_by_"env | grep XAUTHORITY"
export DISPLAY=the_value_i_found_by_"env | grep DISPLAY"
After editing, then this command("env -i /fs/path_to/run_gui.sh") works.
If I logged into a different linux server, I have to change the two variable values in run_gui.sh based on the login. What can I do to make run_gui.sh always work, no need to change each time log in?
Another question I am unclear is, when the command works(same when cron run run_gui.sh work), the GUI is displayed on the screen. I thought when running cron--when it works, the GUI is not visible, because the machine is off. Am I wrong?
I know all these problems are due to my lack of knowledge about X session and XAUTHORITY stuff. I know nothing about them really. I could have to study two or three chapters of book. I am just curious if you could give me a jump start. Thank you very much.
Replies