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



kkyzir@xxxxxxxxx wrote:
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
example:

Environment variables
-------------------------------
Local: NAME="KOSTIS"
Local: HOSTNAME="LOCAL_COMPUTER"
Remote: NAME="HLEKTRA"
Remote: HOSTNAME="REMOTE_COMPUTER"

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
\$REMOTE_COMPUTER > MyFile"

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

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".

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 10.3.1.44 "echo $SSH_CLIENT --- \$SSH_CLIENT"
# sh /tmp/foo
root@xxxxxxxxx's password:
10.254.1.6 4244 22 --- 10.3.1.34 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 ddunham@xxxxxxxx
Senior Technical Consultant TAOS http://www.taos.com/
Got some Dr Pepper? San Francisco, CA bay area
< This line left intentionally blank to confuse you. >
.



Relevant Pages

  • Re: Help with system seeming to return too soon...
    ... So to solve this problem I have to parse the vpnenv.sh script to ... extract all the environment variables that are being set? ... (FYI - vpnenv.sh is not simply a bunch of name=value pairs.) ... the command is finished? ...
    (comp.lang.perl.misc)
  • Re: Cutn Paste and Dragn Drop lost and environment.plist...
    ... When you run this script from the command line, ... of the environment variables used by the command-line session. ... i guess, because it is necessarily WRONG, coming from another session. ...
    (comp.sys.mac.system)
  • OT: Re: /usr/bin/ls: 0403-027 The parameter list is too long
    ... The information that is passed includes the command line ... are setting environment variables in your script?), ... > sole use of the intended recipient/s and may contain material that is ...
    (perl.dbi.users)
  • Re: how to install a command I just made (compiled) on IRIX 6.5
    ... so now I can specify the command line without directory but have to specify the parameter file spec fully. ... Whats happend if a bad guy placed a shell script in your directory called 'ls' and the script contains something like this: ... I had already found out about the environment variables when I tried to get the correct TIMEZONE setup for here. ...
    (comp.sys.sgi.admin)
  • Re: How to read a remote environment variable when executing commands using SSH
    ... Some of arguements provided to the command are read from ... read from the environment variables of the remote computer. ... I want to create a file named MyFile at the remote computer containing ...
    (comp.unix.shell)

Quantcast