Operating System - HP-UX
1752812 Members
5817 Online
108789 Solutions
New Discussion юеВ

Re: How to set DISPLAY variable thru cron when no tty

 
Andrew Merritt_2
Honored Contributor

Re: How to set DISPLAY variable thru cron when no tty

I think you just need to hard-code a value for DISPLAY in the script you run from cron. Since normally you are extracting the information from the login information (from the 'who -u' output), you can't do this for cron since there is no login session associated with running the script from cron. What is it you want to set DISPLAY to when running from cron? That's not something we can tell you; where do you want the output to appear?

If you want to use the same script, then perhaps you test the result of 'tty' to see if you have a tty value; if not use the value you want to use for cron, otherwise continue as you already do.

Andrew
Bill Hassell
Honored Contributor

Re: How to set DISPLAY variable thru cron when no tty

cron does not login. It runs programs on behalf of the user which owns the cron job. And because there is no user present at a keyboard, there is no tty device. That means several things: no tty commands will work, things like tabs, ttytype, tty, etc. It also means that there is no terminal associated with the job that is being run. The who command works only with tty devices, and if you think about it, how would who -muR pick an IP address? There is no one logged into this cron job so it is impossible to pick the 'correct' DISPLAY value.

So as suggested, you must hardcode the DISPLAY variable in your script. HOWEVER: the DISPLAY computer (a PC in this case, which is running Reflection/X) must *never* be logout, shutdown or rebooted. The display screen (which is Windows plus Reflection/X) must always be ready to display something from cron.

Now here's the question: who is going to be sitting in front of the PC when this cron job runs? Does this cronjob require someone to answer questions? Requiring a display device, whether it is a simple ASCII terminal or a graphics program in order to startup seems like a very poor design.


Bill Hassell, sysadmin
Ron Gordon
Advisor

Re: How to set DISPLAY variable thru cron when no tty

I might be missing something, but if you are getting tty error in a cron (which makes sence) and obviously you do not require tty's when running from a cron. In you .profile (or the script which runs the tty command) Put the tty commands in a if stmt to be ignored. ie

if [ "$TERM" -a "$DISPLAY" ]; then
# Set up the terminal:
if [ "$TERM" = "" ]
then
eval ` tset -s -Q -m ':?dtterm' `
else
eval ` tset -s -Q `
fi
stty erase \^H intr \^c kill \^u eof \^d susp \^z echoe echok
stty hupcl ixon ixoff
tabs
set -o vi
prompt="[\!] # "
export PS1=`/usr/ucb/whoami`@:`uname -n`:'$PWD'${prompt}
fi

you could get even fancier by added
if [ ! "$VUE" ]; then
...
fi

Also for interest sake you can get the DISPLAY using the following 1 line as opposed to the 2 lines given above.

DISPLAY=`who -mR | sed "s=.*(==;s=[:)].*=="`:0.0


Frank de Vries
Respected Contributor

Re: How to set DISPLAY variable thru cron when no tty

Hi,
Andrew

You anwser my question with more questions.
Interesting :)

I clarify:

I clearly mentioned it concerned a
startup script for WebSphere.
So any client (pc) that contacts the server
can only receive a session back if
the DISPLAY variable can be set dynamically.
A static DISPLAY just won't cut it.




Look before you leap
Frank de Vries
Respected Contributor

Re: How to set DISPLAY variable thru cron when no tty

Many replies , a lot of ideas, but no solution as yet.

Ron , you missed the point about my tty
command , that was for your benefit, I put
it there purposfully.
Still thanks for you one-liner, I will
add that to my collection :)

Bill:
Your answer seems the most mature.
It is a graphics env in java, trying to
send back a pdf on the fly.
Probably you are right it is poor design,
but it wasn' t mine.

But Java env must be started with
DISPLAY set. Problem in weekend we
stop and start with cron.

Will have to find another way to stop/start,
maybe using rlogin or remsh or telnet localy,
to get this tty anyway.

Thankx
Look before you leap
Andrew Merritt_2
Honored Contributor

Re: How to set DISPLAY variable thru cron when no tty

I'm afraid I don't know what Websphere is, so can't make any assumptions about what it does or how it works. As for asking questions, that seems to be a reasonable way of requesting information :-)

>So any client (pc) that contacts the server
>can only receive a session back if
>the DISPLAY variable can be set dynamically.
>A static DISPLAY just won't cut it.

Right, but what you're doing is restarting the server using cron, at which point you no longer have an active connection, so how do you know what you want to set the DISPLAY variable to? Are you trying to reconnect to a client that's talking to the server, or just restart a client that's run on the server machine and displays on a remote one? Is the remote machine likely to always be up?

Or are you saying you want to kill the server, which will kill the active connection (can there only be one, or many?), and re-open a connection to a client when you restart the server? In that case, when the connection is originally made, you could save the value of DISPLAY to a file, and read it when you restart the server (of course, the client might have gone away in the interim).

I'm sorry, but what you're trying to do with cron is not well described, or perhaps you don't fully understand what cron is and isn't capable of.

Andrew
Frank de Vries
Respected Contributor

Re: How to set DISPLAY variable thru cron when no tty

Andrew

Indeed I underestimated cron limitations,
you are right there. Is was aware of that,
but I was hoping for a workaround, trick,
whatever, cos one never knows everything.

For me it is not necessary to know
beforehand the client who could come
knocking on the web server's door.

As long the DISPLAY variable is dynamically
set.

Compare this to your plain old X11telnet login: If you set (using the nice one liner from Ron) DISPLAY=`who -mR | sed "s=.*(==;s=[:)].*=="`:0.0
then you could login from any client,
and your unix server wouldn't know
which one beforehand, but your display
would be correctly set.

Java works no different, only login is
replaced by software rendered connections
that's all. But still it needs the DISPLAY.

Got the feeling I did more explaining on
this questions then I got ideas from it :) :)




Look before you leap
Andrew Merritt_2
Honored Contributor

Re: How to set DISPLAY variable thru cron when no tty

Frank,
In the case of the telnet login, there is something that indicates where the connection is coming from, and you can set the DISPLAY variable based on that.

But in the case where you are running the script in cron, there is no incoming connection, so I really don't see how you expect to determine what you want DISPLAY to be. That's what I'm trying to understand.

Andrew

Victor BERRIDGE
Honored Contributor

Re: How to set DISPLAY variable thru cron when no tty

Hi again Frank,

My previous post would have solved your problem...
We have a similar situation, and we need a display to capture pdfs...
We use vnc :
http://www.realvnc.com/what.html
e.g.
(define a vnc server as display server)
/home/appoper:vncserver :4

New 'saler:4 ()' desktop is saler:4

Starting applications specified in /home/appoper/.vnc/xstartup
Log file is /home/appoper/.vnc/saler:4.log

/home/appoper:export DISPLAY=localhost:4.0
/home/appoper:xhost +
access control disabled, clients can connect from any host

All the best
Victor
Frank de Vries
Respected Contributor

Re: How to set DISPLAY variable thru cron when no tty

Andrew

I think you understand it, but now just
translate what you know to the java virtual machine which also can act as login daemons (only sofware rendered) as opposed to inetd deamon that listens to your login and spawns a getty and .profile in unix when connecting.

Imagine this concept but transpose it
to java's logics and you'll see
it is no different in essence.

As to the fact that is started by cron,
can maybe be compared when you
boot a unixserver there is also no user
connecting nor involved. Still it is quite legal to put in the root profile (other
other user's profile) the DISPLAY command dynamically (see Ron's oneliner), and then
connecting from a pc with e.g. reflectionX ,
it will attach a tty and with that with
who -u you can obtain the hostname of
the client. so DISPLAY can be programmed
on this basis with variables, except
thru cron unfort.

Hope u c :) :)


Look before you leap