How to read a remote environment variable when executing commands using SSH

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Hello everbody! I want to execute a command to a remote computer using
SSH. Some of arguements provided to the command are read from
environment variables from the local computers, and some arguements are
read from the environment variables of the remote computer. To give an

Environment variables
Local:      NAME="KOSTIS"
Remote:   NAME="HLEKTRA"

What I want to do
I want to create a file named MyFile at the remote computer containing
the phrase "KOSTIS is logged to the REMOTE_COMPUTER"

The command I execute
 ssh -i identity_file -l username "echo $NAME is logged to the

When I type the command at the shell and I run it, it works perfectly.
The problem is that if I type the command inside a script and I execute
the script, the phrase that is written to the remote file is "KOSTIS is
logged to the LOCAL_COMPUTER".

Any help would be appreciated!!!!!

Re: How to read a remote environment variable when executing commands using SSH wrote:
Quoted text here. Click to load it

Perhaps you mean... 'logged to the $HOSTNAME > MyFile' ?

Quoted text here. Click to load it

Can you show the exact script?  Is this sh/bash on both sides?

I can't reproduce your problem.  It appears to work the same for me from
the commandline and a script.

# cat /tmp/foo
ssh "echo $SSH_CLIENT --- $SSH_CLIENT"
# sh /tmp/foo
root@'s password: 4244 22 --- 1023 22

I'm relatively certain that any issues you have here will be shell
related and not have anything to do with ssh.

Darren Dunham                                 
Senior Technical Consultant         TAOS   /
Got some Dr Pepper?                           San Francisco, CA bay area
         < This line left intentionally blank to confuse you. >

Site Timeline