I have script on target Linux (RedHat, PC_A) which I would like to execute from source Linux (RedHat, PC_B) during remote login session.
I'm trying to execute following command :
[user2@PC_B] ssh <user1>@<PC_A> "cd /home/<user1>; source /home/<user1>/.bashrc; ./<script.sh>;"
but as soon as I login and execute I'm receiving multiple errors,
"Environment variable USER1_ROOT not defined
./stoprun: line 6: psrun: command not found
./omcserver: error while loading shared libraries: libocci.so.11.1: cannot open shared object file: No such file or directory
./wdc: error while loading shared libraries: libmutil.so: cannot open shared object file: No such file or directory (...)
Note 1: <user1> is already authenticated without the password (added to authorized users on PC_A), there is no problem here; e.g. I can execute [<user2>@<PC_B> ~]$ ssh <user1>@<PC_A> "cd /home/<user1>; ls -ls; date" without any errors
Note 2: I'm not concern at all about errors like, "./stoprun: line 6: psrun: command not found" nor "error while loading shared libraries" (I just showed them as example of the consequence of the problem with passing properly variables between PC_A and PC_B) and I need to pass multiple variables within single ssh session. My main concern is Error message "Environment variable xxx_xxx not defined".
How to properly pass entire environment from target/server (PC_A) to source/client (PC_B) during one single ssh session ?
Note 3: on both hosts (PC_A) and PC_B I already set
[root@PC_A ~]# cat /etc/ssh/sshd_config | grep User
PermitUserEnvironment yes
Note 4: same script executes without any error, problem or missing libs when executed from source host (PC_A)
[<user1>@<PC_A> ~]$ cd /home/<user1>
[<user1>@<PC_A> ~]$./<script.sh>;
/2/ on PC_B added variables in /etc/ssh/ssh_config PC_B :
[root@<PC_B> ~]# cat /etc/ssh/ssh_config | grep SendEnv
SendEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES
SendEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT
SendEnv LC_IDENTIFICATION LC_ALL
SendEnv TEST
[root@<PC_B> ~]#
/3/ Specified a customized environment variables in ~/.ssh/environment
[root@<PC_B> ~]# cat /home/user2/.ssh/environment
LANG=en_us.utf-8
TEST="test"
[root@<PC_B> ~]#
Note: LANG environment variable is already defined on both PC_A and PC_B, so I added one more "independent" variable TEST
/4/ executed ssh with adding verbosity -v
[user2@<PC_B> ~]$ ssh -v <user1>@<PC_A_IP_Address> "cd /home/<user1>; echo $TEST; echo $LANG"
OpenSSH_4.3p2, OpenSSL 0.9.8e-fips-rhel5 01 Jul 2008
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Connecting to <PC_A_IP_Address> [<PC_A_IP_Address>] port 22.
debug1: Connection established.
debug1: identity file /home/user2/.ssh/identity type -1
debug1: identity file /home/user2/.ssh/id_rsa type 1
debug1: identity file /home/user2/.ssh/id_dsa type -1
debug1: loaded 3 keys
debug1: Remote protocol version 2.0, remote software version OpenSSH_4.3
debug1: match: OpenSSH_4.3 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_4.3
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-cbc hmac-md5 none
debug1: kex: client->server aes128-cbc hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Host '<PC_A_IP_Address>' is known and matches the RSA host key.
debug1: Found key in /home/user2/.ssh/known_hosts:1
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,gssapi-with-mic,password
debug1: Next authentication method: gssapi-with-mic
debug1: Unspecified GSS failure. Minor code may provide more information
No credentials cache found
debug1: Unspecified GSS failure. Minor code may provide more information
No credentials cache found
debug1: Unspecified GSS failure. Minor code may provide more information
No credentials cache found
debug1: Next authentication method: publickey
debug1: Trying private key: /home/user2/.ssh/identity
debug1: Offering public key: /home/user2/.ssh/id_rsa
debug1: Server accepts key: pkalg ssh-rsa blen 277
debug1: read PEM private key done: type RSA
debug1: Authentication succeeded (publickey).
debug1: channel 0: new [client-session]
debug1: Entering interactive session.
debug1: Sending environment.
debug1: Sending env LANG = en_US.UTF-8
debug1: Sending command: cd /home/<user1>; echo ; echo en_US.UTF-8
en_US.UTF-8
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
debug1: channel 0: free: client-session, nchannels 1
debug1: Transferred: stdin 0, stdout 0, stderr 0 bytes in 0.1 seconds
debug1: Bytes per second: stdin 0.0, stdout 0.0, stderr 0.0
debug1: Exit status 0
[user2@<PC_B> ~]$
/5/ I restarted sshd service on both PC_A and PC_B
[root@<PC_A> ~]# service sshd restart
Stopping sshd: [ OK ]
Starting sshd: [ OK ]
[root@<PC_A> ~]#
/6/ Checking Environment variables from PC_A (a) as root user
[root@<PC_A> ~]# echo $TEST
[root@<PC_A> ~]# echo $LANG
en_US.UTF-8
(a) as non-root user
[root@<PC_A> ~]# exit
logout
[<user1>@<PC_A> ~]$ echo $TEST
[<user1>@<PC_A> ~]$ echo $LANG
en_US.UTF-8
[<user1>@<PC_A> ~]$
And here is the issue : somehow only one environment variable is send and it seems immediately replaced within open ssh session by its defined value and while other variable vanished (blank value)
"debug1: Sending env LANG = en_US.UTF-8
debug1: Sending command: cd /home/<user1>; echo ; echo en_US.UTF-8
en_US.UTF-8"
Note #1 I added also all combinations here , and none of them work :
[root@<PC_B> ~]# cat /home/user2/.ssh/environment
LANG=en_us.utf-8
TEST=test
[root@<PC_B> ~]#
[root@<PC_B> ~]# cat /home/user2/.ssh/environment
set LANG=en_us.utf-8
set TEST=test
[root@<PC_B> ~]#
[root@<PC_B> ~]# cat /home/user2/.ssh/environment
declare -x LANG="en_us.utf-8"
declare -x TEST="test"
[root@<PC_B> ~]#
script.sh. Also, is the shebang using/bin/bashor/bin/sh?#!/bin/bash~/.bash_profileand it is very simply script with copy, cd commands , simple timer loop and executing directly other scripts". Second line with~/.bash_profileI added for troubleshooting purpose, hoping it will resolve issue. But problem persist even without~/.bash_profileafter shebang.