Operating System - HP-UX
1843944 Members
2356 Online
110226 Solutions
New Discussion

passed environment variables when using remsh

 
SOLVED
Go to solution
Marc Ahrendt
Super Advisor

passed environment variables when using remsh

what environment variables, if any, are preserved when using remsh?

hostA (user toad)> remsh hostB -l frog "echo what gets carried over from user toad for user frog?"

i know most are not ...like DISPLAY, SHELL, etc...

thx, marc
hola
10 REPLIES 10
Jeff Schussele
Honored Contributor

Re: passed environment variables when using remsh

Hi Marc,

AFAIK it passes none.
Instead it will source the remote user's appropriate .profile .kshrc .cshrc - whatever is appropriate for that user's shell.
IF you need a specific env set up you'll need the remote command to source a file or run a script from the remotely called script.

Rgds,
Jeff
PERSEVERANCE -- Remember, whatever does not kill you only makes you stronger!
Fred Ruffet
Honored Contributor

Re: passed environment variables when using remsh

Remsh will open a login shell on the other side, and environnement will be as if you logged with telnet.

If you want to have environment variables go to the other side, pass them as argument to a script.

Regards,

Fred
--

"Reality is just a point of view." (P. K. D.)
Bill Hassell
Honored Contributor

Re: passed environment variables when using remsh

remsh does not login like rlogin or telnet, so it has a VERY MINIMAL environment, nothing from the local system. To see the environment:

remsh systemb env
remsh systemb set

The first shows exported variables and the second shows all variables. If you assume that nothing is setup when you use remsh, then you'll be safe. You'll have to run /etc/profile and .profile as part of your remsh command. Otherwise, you have to use rlogin to get the remote user's environment.

Carrying over local variables doesn't always make any sense (ie, SHELL is meaningless on the remote system unless it happens to match). DISPLAY makes sense but only telnet can transport a local variable (it happens to be TERM), remsh cannot. The important difference about remsh is that it is not a terminal process...it looks like one but if you try this:

remsh systemb who -muR

you'll get an error that who cannot identify the incoming terminal connection. So the key is to carry the DISPLAY variable in your command as in:

remsh systemb /usr/bin/X11/xclock -display $DISPLAY

Now this ASSUMES that DISPLAY is set to your IPaddr:0.0


Bill Hassell, sysadmin
Marc Ahrendt
Super Advisor

Re: passed environment variables when using remsh

Jeff, thx but what is AFAIK? and also your comment is incorrect about sourcing the .profile (remsh does not do that automatically) ...see Bill's comments below

Fred, thx because your comment made me just realize my mistake in posting my question! the issue is not with remsh but RLOGIN!

Bill, thx for the great feedback but again my mistake was that i meant RLOGIN not remsh

1) i am using rlogin ...not remsh as i wrongly stated earlier (sorry)

2) i am using the following command
rlogin hostB -l frog

3) the account frog on hostB is a "captive" account where everything is done in .profile and exits the account after .profile is done

4) Bill made a statement that is really what i mean ...i want to "transport a local variable" using rlogin to the .profile on the remote host, but i just do not know what local variables qualify!?! i just want to know if any qualify.
hola
Patrick Wallek
Honored Contributor

Re: passed environment variables when using remsh

AFAIK = As Far As I Know

It doesn't matter which of the r* services (remsh, rlogin, whatever) you use, the answer is the same. Nothing is taken from one machine to another.
Steven E. Protter
Exalted Contributor

Re: passed environment variables when using remsh

The script or process you run after issuing the remesh command must set all needed variables.

There is no alternative and passing DISPLAY for example from one machine to another won't work anyway.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Jeff Schussele
Honored Contributor

Re: passed environment variables when using remsh

Hi (again) marc,

Well I should have been a little more explicit.
IF the default remote shell is /usr/bin/sh or /usr/bin/ksh THEN the following will run it

remsh hostb . .profile 2>&- \; rem_command

and set up the env before the command is executed. And of course that command can simply be a shell.
I really would look at setting up the env properly on the remote host using remsh rather then hoping you can pass env vars in rlogin because I just don't think it can be done.

Rgds,
Jeff

P.S. AFAIK - As Far As I Know
PERSEVERANCE -- Remember, whatever does not kill you only makes you stronger!
Bill Hassell
Honored Contributor
Solution

Re: passed environment variables when using remsh

OK, remsh propagates nothing because it does not have a terminal concept. rlogin does have a terminal concept (it is interactive) so (see man rlogin) TERM is propagated to the remote system. But that's all. This is identical to telnet which is also proagated to the remote machine.

However, that is not a good thing anymore. In old Unix days, terminal characteristics such as baud rate, parity, etc, needed to be propagated and each flavor of the rlogin or telnet daemon would use these to setup local behavior. Today, the underlying (and rather detailed) protocol handshake that you never see will handle this. But it leaves TERM defined at the remote system *prior* to running /etc/profile and .profile--this is not good. For instance, if you're on a Linux box and telnet/rlogin to HP-UX, /etc/profile will inherit TERM=linux, a bad thing because the terminfo library knows nothing about "linux" as a terminal (untic linux). And Windows may set something like TERM=ansi or whatever terminal emulator you are using on the PC.

So /etc/profile should be coded to NEVER use what it inherits for TERM. Instead, let ttytype probe your terminal automatically for the TERM variable. Get rid of the: if [ $TERM = something ] and replace all of that with:

exec $(ttytype -s)

Now your terminal setting on the remote side will be correct. ttytype will set TERM LINES and COLUMNS automatically. Run ttytype -s to see what it does.


Bill Hassell, sysadmin
Biswajit Tripathy
Honored Contributor

Re: passed environment variables when using remsh

Another way to pass env variable to the remote
system would be the following:

$ remsh REMOTE_MACH_NAME 'xclock'
Error: Can't open display

$ remsh REMOTE_MACH_NAME 'DISPLAY=display_mach:0.0 xclock'
.. works like magic :-)


- Biswajit
:-)
Marc Ahrendt
Super Advisor

Re: passed environment variables when using remsh

thx Biswajit but i was aware of remsh usage ...just not ware of the what environment variables got "transported" over (seems for all practical purposes that its none) when using it or, of more interest to me, rlogin

thx Patrick/Steve/Jeff for the feedback

thx Bill for the detail/explanation i was looking for about not only the sole env var. TERM that does qualify, but just that it is a best practice (as others stated above) to use the r* commands with needed env.s on the remote account itself
hola