Operating System - HP-UX
1834332 Members
1986 Online
110066 Solutions
New Discussion

Re: Adding addition VARIABLE to default env

 
SOLVED
Go to solution
Belinda Dermody
Super Advisor

Adding addition VARIABLE to default env

I have two HP servers running HP10.20
if I run the command
remsh cancun env it returns the basic info
PATH=/usr/bin:etc
LOGNAME=jmarrion
SHELL=/usr/bin/sh
HOME=/jmarrion
PWD=/home/jmarrion
TZ=EST5EDT

What I would like is to have another one
VAXSVR=maui

I have added this to /etc/profile but it only display the variable if the user logins into the platforms. With the remsh command it doesnt show.
9 REPLIES 9
Jeff Machols
Esteemed Contributor

Re: Adding addition VARIABLE to default env

remsh uses the default shell csh. try added the variable to the .cshrc in the users home directory
linuxfan
Honored Contributor

Re: Adding addition VARIABLE to default env

Hi James,

By default, remsh uses the path (from the man page)/usr/bin:/usr/ccs/bin:/usr/bin/X11

to execute another profile

remsh cancun . ~/.profile ; env

or if you have a file where you have all your environment variables stored, source it and then check your env

remsh cancun -n ". envfile ; env"

Check the man page of remsh for more information

-HTH
Ramesh
They think they know but don't. At least I know I don't know - Socrates
linuxfan
Honored Contributor

Re: Adding addition VARIABLE to default env

Hi James,

One more thing, if you are just looking for this one variable then you could try something like,

remsh cancuun "export VAXSRV=maui ; env"

-Regards
Ramesh
They think they know but don't. At least I know I don't know - Socrates
Sridhar Bhaskarla
Honored Contributor

Re: Adding addition VARIABLE to default env

How are you getting the variables through remsh?.

remsh doesn't execute your .profile.

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: Adding addition VARIABLE to default env

Hi:

One approach is to add your variable to the remote users .profile.

something like this:
remsh remotehost . .profile 2>&- \; mycmd.sh

The 2>&- discards any error messages genererated by terminal related commands like stty when stdin is not a terminal. mycmd.sh is then run with the environment setup.

You could alter the .profile to test for this condition and bypass the stty stuff and not have to use the 2>&- stuff.

Like this:
if [ -t 0 ]
then
stty ...
tabs ...
fi

I normally do the in my .profiles anyway.
You could also include an entry to source your variables from a localfile

. /usr/local/bin/env.sh

and env.sh would look like this
VAXSVR=maui
HOST=`usr/bin/hostname`
export VAXSVR HOST

Just don't put an exit statement at the end of this sourced file.

Regards, Clay
If it ain't broke, I can fix that.
Belinda Dermody
Super Advisor

Re: Adding addition VARIABLE to default env

Thanks for all the response, most likely I didn't express myself correctly. I have multiple VAX servers for prod,test and development and which unix platform the user is running on depends upon which VAX server to send the output.

1. For one thing we all use sh or ksh here.

2. I have added the VAXSVR variable to /etc/d.profile so it is set in everyones /home/.profile

3. What I do not want to do is to have to source the .profile for each script that I have written to set the VAXSVR variable on remote processing.

4. What I was hopping for, that there is a way to ADD the VAXSCR variable to be set like PATH, SHELL,HOME, PWD,TZ. They seem to me to be system defaults
Belinda Dermody
Super Advisor

Re: Adding addition VARIABLE to default env

Clay

When I execute the following
remsh cancun . .profile 2>&- \; /tmp/t.sh
it returns fd = 2
Sridhar Bhaskarla
Honored Contributor

Re: Adding addition VARIABLE to default env

James,

Set it in /etc/profile. If I understood correctly, you want the users to use $VAXVAR variable to do remsh.

Like

$remsh $VAXVAR -l login some_command.

You need to set it in /etc/profile not d.profile.

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
A. Clay Stephenson
Acclaimed Contributor

Re: Adding addition VARIABLE to default env

Hi again James:

I did the 2>&- \; from memory but it turns out that this old head was ok. I just tried the exact same syntax on a pair of my boxes and all was ok. I rather suspected you had multiple
servers and that is why I included setting HOST in my earlier example. You could do the same thing and have your .profile run hostname to set that for you.

The exact syntax I used was:
remsh bugs . .profile 2>&- \; ./test.sh

Test shell in my home directory looked like this:

#!/usr/bin/sh

HOST=`/usr/bin/hostname`
echo "This is a test from ${HOST}."
exit 0

The output when run using the above remsh was
"This is a test from bugs." - just as expected.

Regards, Clay
If it ain't broke, I can fix that.