Help: use cron to run a GUI program

May 11th, 2012 - 08:57 pm ET by www | Report spam
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.
email Follow the discussionReplies 2 repliesReplies Make a reply

Replies

#1 www
May 11th, 2012 - 10:57 pm ET | Report spam
Another related question is: from my home computer, I use Putty to connect to the company's Linux machine. However, the terminal cannot open any GUI program (or I don't know how to configure Putty to run GUI program). Is there a way that by defining DISPLAY and other environment variables, I can execute run_gui.sh? I don't need to see the GUI. The GUI program is an automatic program, no human interaction is needed. It will shut down automatically after it finishes. Again, I don't need to see the GUI program by my eyes.

Thank you so much for your help.

Similar topics