LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 08-29-2004, 05:39 AM   #1
ericcarlson
Member
 
Registered: Jan 2002
Posts: 162

Rep: Reputation: 30
X apps fail when run from cron jobs


The app is the java phone emulator and its being run from a *.sh file to run through some automated tests overnight. System is RH FC2 Final.

If I ssh into the server and run the batch I get lots of errors from java relating to not being able to create display contexts. Fair enough, I'm only on a terminal so I'd be suprised if it did work. When I'm actually at the server on KDE if I bring up a terminal, run the same command up pops the GUI window and the app runs fine. However, when the cron fired the same batch overnight I saw in the log the same errors I got when ssh'ing in, IOW it too had no access to X (?). This puzzled me because it was being run locally and X is running permanently.

Has anyone seen this before and got any ideas please? Thanks...
 
Old 08-29-2004, 02:36 PM   #2
jailbait
LQ Guru
 
Registered: Feb 2003
Location: Virginia, USA
Distribution: Debian 12
Posts: 8,340

Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
"If I ssh into the server and run the batch I get lots of errors from java relating to not being able to create display contexts. Fair enough, I'm only on a terminal so I'd be suprised if it did work. When I'm actually at the server on KDE if I bring up a terminal, run the same command up pops the GUI window and the app runs fine. However, when the cron fired the same batch overnight I saw in the log the same errors I got when ssh'ing in, IOW it too had no access to X (?). This puzzled me because it was being run locally and X is running permanently."

You can think of the cron job as a user when looking at this problem. Each user starts X Window or uses a terminal or whatever independently of what the other users happen to be doing. The cron job is running from a bash shell regardless of whether other users happen to be using X Window. Since the cron application is not running under X Window it fails in the same way as if a user tried to run the application without first starting X Window.

---------------------------
Steve Stites
 
1 members found this post helpful.
Old 08-31-2004, 08:34 AM   #3
gatito
LQ Newbie
 
Registered: Aug 2004
Distribution: debian, suse
Posts: 2

Rep: Reputation: 0
hi jailbait
itīs possible to start a script (needs xserver) with cron?
in my case i need to start a browser and run a php script, for that i have a little script that starts the browser and the php script.
if i run it from the console and manually it works fine, but cron wont do that and gets this error `cant connect to x server`.
but x server is started and im logged in as the user that starts the cron jobs.
and this user is also allowed to use the xserver(xhost + user)
maybe you know a solution....
thanx in advance
 
Old 08-31-2004, 01:32 PM   #4
jailbait
LQ Guru
 
Registered: Feb 2003
Location: Virginia, USA
Distribution: Debian 12
Posts: 8,340

Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
"but x server is started and im logged in as the user that starts the cron jobs.
and this user is also allowed to use the xserver(xhost + user)"

The cron jobs are started by the cron daemon, not by any user. You cannot log in as cron.

"itīs possible to start a script (needs xserver) with cron?"

The only daemon that can start X Window for cron's use is the cron daemon. I have no idea how to do that.

-------------------
Steve Stites
 
Old 05-31-2009, 05:26 PM   #5
Mihai Cartoaje
LQ Newbie
 
Registered: May 2009
Posts: 3

Rep: Reputation: 1
I was able to run X-Windows applications from a Cron script. Here's how:

Use the command localhost to find the name of your host.

Use the command xhost to allow all connections from your host:

xhost +host

In the Cron script, set the DISPLAY environment variable:

DISPLAY=host:0.0
export DISPLAY

For debugging, you can use the command

ps -e

to find your terminal's device file. For example my terminal is /dev/pts/2 . So in the Cron script you can launch an application like,

/usr/X11R6/bin/gv >/dev/pts/2 2>/dev/pts/2

Cron scripts don't automatically look in /usr/X11R6/bin so one solution is to write the full path of X-Windows applications.

Last edited by Mihai Cartoaje; 06-01-2009 at 02:19 PM.
 
1 members found this post helpful.
Old 06-16-2017, 12:43 PM   #6
Can-ned Food
LQ Newbie
 
Registered: Apr 2015
Distribution: GNU→TT
Posts: 7

Rep: Reputation: Disabled
A simple way to make this work, when on a local machine which already has a local user configured and able to access the X Server, is to do something like this with the Cron job line in /etc/crontab:
Code:
* * * * *   whatever-username   DISPLAY=:0 XAUTHORITY=/home/whatever-username/.Xauthority whatever-xappl
I.e. the execution environment of a Cron job is rather bare as compared to your usual interactive or login environment, and it lacks those two envars, DISPLAY and XAUTHORITY.
I won't go into many of the particulars or nuances here, because there are quite a lot of them. A few installations have variable paths to their Xauthority data, for one thing. Another thing is that remote users, e.g. via ssh sessions, can't rely on the usual value for DISPLAY.
You might need to write some procedures into your script rather than simply rely on envar definitions added to the commandline of a Cron job.

A lot of that information is available elsewhere on the internet, but suffice it to say that I hope at least a few runaday users, and maybe a few novice power users, might be helped by me mentioning this tidbit here. Cheers.
 
Old 06-16-2017, 01:02 PM   #7
ericcarlson
Member
 
Registered: Jan 2002
Posts: 162

Original Poster
Rep: Reputation: 30
13 years ... finally I can run the j2me emulator from cron

Hmm, j2me? Seemed promising once. At least I can prove I really was doing automated mobile tests for all those years!

Thanks for the response mate, see you back here in 2030 :-)
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
simple "echo > qbc" cron jobs doesn't run shole Linux - Newbie 3 09-23-2006 02:09 PM
Cron Jobs XaViaR Linux - General 1 06-23-2005 06:57 PM
cron jobs work fine when invoked from webmin but fail on schedule jillu Linux - Enterprise 3 01-20-2005 01:34 PM
Can't run cron jobs as user, only root Kropotkin Linux - Newbie 5 11-10-2004 09:30 AM
Cron jobs, will they run when not logged in? nextekcarl Linux - General 18 03-30-2004 10:28 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 09:18 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration