Operating System - HP-UX
1819910 Members
2511 Online
109607 Solutions
New Discussion юеВ

Re: ssh sets up environment variables differently

 
SOLVED
Go to solution
Mel Burslan
Honored Contributor

ssh sets up environment variables differently

I know the subject is a little vague but here is the explanation:

ssh oracle@host lsnrctl stop

ksh: lsnrctl: not found


ssh oracle@host

host# lsnrctl stop

LSNRCTL for HPUX: Version 9.2.0.7.0 - Production on 06-JUN-2006 14:23:53

Copyright (c) 1991, 2002, Oracle Corporation. All rights reserved.

Connecting to (ADDRESS=(PROTOCOL=IPC)(KEY=BWD.WORLD))
The command completed successfully

ssh oracle@host "env | grep PATH"
PATH=/usr/bin:/bin:/usr/sbin:/sbin:/opt/ssh/bin

ssh oracle@host

host# env | grep PATH
PATH=/oracle/SID/920_64/bin:/usr/sap/SID/SYS/exe/run:/usr/bin:/usr/ccs/bin:/usr/local/bin:/usr/contrib/bin:/opt/hparray/bin:/opt/nettladm/bin:/opt/upgrade/bin:/opt/fcms/bin:/opt/pd/bin:/opt/resmon/bin:/opt/gnome/bin:/opt/perf/bin:/opt/ignite/bin:/opt/mozilla:/usr/bin/X11:/usr/contrib/bin/X11:/opt/graphics/common/bin:/opt/prm/bin:/usr/sbin/diag/contrib:/opt/mx/bin:/opt/wbem/bin:/opt/wbem/sbin:/opt/hpnpl//bin:

why are they different and what variable in which configuration file controls this difference.

Thanks for all the responses in advance
________________________________
UNIX because I majored in cryptology...
8 REPLIES 8
TwoProc
Honored Contributor

Re: ssh sets up environment variables differently

Mel, I would think that what's happening is that when you invoke a full shell, then your .profile and .kshrc (or .cshrc) is being read, and then you can type your commands. When you're ssh'ing over to another computer and giving commands, I'm thinking that one or both of the two files mentioned above is not being read.

Instead make a command file to do the shutdown, and put the environment variables in the command script file.

E.g.
#!/bin/ksh
# listener shutdown for MYDB
#
ORACLE_HOME=/u1/oracle/MYDB/9.2.0
TNS_ADMIN=${ORACLE_HOME}/network/admin
PATH=${PATH}:${ORACLE_HOME}/bin
export ORACLE_HOME TNS_ADMIN

lsnrctl stop

We are the people our parents warned us about --Jimmy Buffett
Paul F. Carlson
Valued Contributor

Re: ssh sets up environment variables differently

You could add your enviromental variables to ~/.ssh/environment for your oracle user. Then in sshd_config set PermitUserEnvironment yes and restart sshd.

See man sshd_config and man ssh.

-Paul
Link down -- cable problem?
Paul F. Carlson
Valued Contributor

Re: ssh sets up environment variables differently

Note: That should be ~oracle/.ssh/environment
Link down -- cable problem?
Mel Burslan
Honored Contributor

Re: ssh sets up environment variables differently

John,

Thanks for the suggestion but the remote account as you can guess belongs to the dba's and I do not want to make any changes as they can break something and I do not like to be at the target end of a pointing finger.

Paul,

Due to pretty much the same thing above, I do not want to mess with their account settings.

All in all, I want the ssh session having the same environments regarless I am in an iteractive session or remote command execution mode. Can this be accomplished without creating new files or changing the environment variables related to oracle ?
________________________________
UNIX because I majored in cryptology...
Bill Hassell
Honored Contributor
Solution

Re: ssh sets up environment variables differently

An interactive shell prompt is a very different environment than running a remote command -- you're not starting a login shell so two very important files are skipped: /etc/profile and ,profile (and if they use a different shell, other profile files). So to set the same environment, you need to source the same profiles that an interactive login sources. So your remote command will need several commands on the same line, something like:

ssh '. /etc/profile;. $HOME/.profile; remote_command parms'

The single quotes pass everything over to the remote system and the multiple commands will emulate a login shell environment.


Bill Hassell, sysadmin
Paul F. Carlson
Valued Contributor

Re: ssh sets up environment variables differently

Mel,

See man sshd under "Login Process". The basic environment it sets up is determined at compile time, then it sets up what is in $HOME/.ssh/environment. The last step is "Runs user's shell OR command".

-Paul
Link down -- cable problem?
FrankZhou
New Member

Re: ssh sets up environment variables differently

Bill is Guru!! Thank you!

After spend 3 hours, finally got your post.

Now my command works like

ssh -q -o 'StrictHostKeyChecking no' -o 'BatchMode yes' oracle@$v -i /home/oracle/.ssh/open-key '. /etc/profile;. /home/oracle/.profile;sqlplus -V' >> $LOGFILE

Hahahahaha! Excellent! Thank you Bill!
Mel Burslan
Honored Contributor

Re: ssh sets up environment variables differently

thread closed
________________________________
UNIX because I majored in cryptology...