Operating System - HP-UX
1828330 Members
4176 Online
109976 Solutions
New Discussion

How to set DISPLAY variable thru cron when no tty

 
Frank de Vries
Respected Contributor

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

I appreciate your genuinity :)

Just feel that we are off a tangent,
all I wanted was to know possible
workaround.

The setting of the DISPLAY in a script
that stops and starts WebSphere in de
weekend fails. IT ONLY FAILS IN THE
CRONJOB not otherwise !!!!!!!!!!

Thus this line fails when run in the
script as a cronjob:
DISPLAY=`who -mR | sed "s=.*(==;s=[:)].*=="`:0.0

And I agree with you that Bill provided
the best answer sofar. There is no tty
(Matrix: there is no spoon)

However, I have not a problem running
the stuff outside cron nor during a
reboot of the server. Thus I repeat
only when run through cron.

And Java is quite capable of responding to
software rendered connections without prior
knowledge and quite dynamically reply with
stuff using unix generic X11.

So , I don't realy have a problem.

Thanks for looking after me so much,
love and peace :)



Look before you leap
Victor BERRIDGE
Honored Contributor

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

Hi again Frank,
You could give a try with xvfb (which can be configured a similar way and may be accepted your security staff..)
To answer your question:
No not used by cron nor startup because they are configured in MCSG packages (4 node cluster) and we use controlm as scheduler...
but what I can say is that stop/start are called by batch script, so it should work in your startup/stop scripts


All the best
Victor
Andrew Merritt_2
Honored Contributor

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

Hi Frank,
I don't want to give up on this, but I'm not sure how I can convince you that you've already had the answer. I'll have what is probably one last go.

I fully understand that the problem only happens with cron. What you're not seeing is that it is exactly because running from cron is different, since the information available at the time is different.

We're not going off at a tangent, this is the heart of the matter.

When the script is run due to an incoming connection, information about that connection can be used to determine what value to set DISPLAY to, to get the window to go to the right place.

When you run the script from cron, there is NO incoming connection. In that circumstance, where do you want the window to appear? There just isn't any information that the script can use to decide this. Perhaps you don't fully realise what 'cron' is doing. It does not create a login session, it just runs a script on the server, with the permissions of the specified user, but with no associated terminal.

You mention running the script during a reboot of a server, but from other comments you have made I think you are referring to the 'profile' file for the root user, which does not get executed until someone logs in, so at that point there is a value for 'tty'. If you mean something different, please explain how it gets a value for 'tty'.

You say that java is capable of responding to 'software rendered connections', but I repeat, there is NO CONNNECTION when cron runs the script.

I'm afraid I'm failing to get across something fundamental about how cron is working, and why this explains what you are seeing, and why it just doesn't seem possible to do what you want, without making an assumption about where you want the display window to pop up when cron creates it.

All I can suggest is for you to try to explain where it is you want the server to connect to when cron runs the script. Bear in mind that there is no client running at this time requesting a connection (which is the case in all the other examples you give; normally the script is being run in response to a client doing something).

Andrew
Frank de Vries
Respected Contributor

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

Hi again Andrew

I appreciate our reply.

Do you consider that cron is
used to start a application,
albeit in background.

Tes, we do login !!
To the WebSphere server (WS).
(provided it started okay)

Once we are logged in (WS) we have a whole lot of functionality at the application side some of which uses the X11 service and as you know the DISPLAY is vital there.
Well the rest you know.

What bothers me is that even thought I am aware that cron has no tty, still it could pass on the variable in the background job 'as is' instead to foobar it.

I appreciate it is different with cron
because the information available is
different.

I will have to find another solution,
coming from a complete different angle.

Still I feel it is always worthwhile to
test conventional ideas here at the forum.
It is not the first nor the last time some
vested mythical believe about what unix can
and cannot do is shattered to pieces.

Ok not this time it seems:)
Thanks Andrew for spending your time
on this anyway.







Look before you leap
Andrew Merritt_2
Honored Contributor

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

>What bothers me is that even thought I am
> aware that cron has no tty, still it could
> pass on the variable in the background job
> 'as is' instead to foobar it.


Yes, but... cron doesn't have any value to pass on in the DISPLAY variable. It is starting up in isolation. What value do you think that DISPLAY has, that can be passed on 'as is'?

cron can set an arbitrary value for DISPLAY and pass it on, but we return to the point which is that as far as I can see it has no way of determining what value to set it to.

Where do you think the X11 window will be displayed when cron runs the script?

Andrew
Frank de Vries
Respected Contributor

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

Andrew

No, DISPLAY has not value it must be
a formulea. But it certainly should
not have a fixed value, it must be
dynamically exported.

Compare it to the PS1 variable for prompt.
It is not supposed to be fixed either.

To answer your question on X11.
So the value of the formulea DISPLAY is
filled in.
An example:
You can test this with the hpterm command.
Log in from various terminals, put at
the end of the password file not /sbin/sh
but ../x11/hpterm -toolkitoptions and
it will send it. In reflectionX you can
even make a macro that when the pc boots
you get the application, user wouldn't be
none the wiser it came from a Unix box.

(I know that is pretty insecure, that is why we prefer to do it on software level
Thus replace the above idea with javaX)

BUT, and here we go again, the value can
only be resolved if there is a tty.
Which funny enough there is after cron has
started the Application, because if you
check with who -u you see who is connected.
But the DISPLAY formulea is foobar by cron,
wam bam thank you mam

Cron is Gregory Peck;)
and I am Brahms and List !!



Look before you leap
Andrew Merritt_2
Honored Contributor

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

Frank,
I'm sorry, I've failed. I'm just not able to explain so you can understand. I can't quite put my finger on what it is you're missing, but the issue is that when cron runs the script, there is no connection, so no 'tty' or any other connection from which to deduce a DISPLAY value. Yes, when you connect with hpterm, or look after a client has connected to the WS server, then you have a value, but that is not so when cron runs the script. Imagine the script running on a server with no cables (apart from power!) connected, and that is the situation.

I'm really giving up now, this is my last post on this!

Andrew