LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   unable to retrive profile variable using ssh (https://www.linuxquestions.org/questions/linux-newbie-8/unable-to-retrive-profile-variable-using-ssh-4175454180/)

kumarjohn 03-15-2013 08:19 AM

unable to retrive profile variable using ssh
 
unable to retrive the profile vaiable using ssh.


server2 ==> user apptst ==> bash profile has $APPHOME variable.

was trying to retrive the value from server1 using ssh but failed.

used below options

Quote:


server1> ssh apptst@server2 'echo $APPHOME'

server1> ssh apptst@server2 echo '$APPHOME'

server1> ssh apptst@server2 echo "$APPHOME"

server1> ssh apptst@server2 "echo $APPHOME"

when tried

Quote:


server1> ssh apptst@server2 ls -ld $APPHOME

it works fine.

any suggestions what is misisng and how can get the variable from server2.

Best Regards,
KJ.

allend 03-16-2013 12:58 AM

I suspect that $APPHOME variable is defined on server1 but not on server2.
Quote:

server1> ssh apptst@server2 ls -ld $APPHOME
With that command, the $APPHOME is expanded by the shell on server1
Quote:

server1> ssh apptst@server2 'echo $APPHOME'
With that command, the $APPHOME is expanded by the shell on server2

shivaa 03-16-2013 01:06 AM

What do you get when you run?
Code:

server1> ssh apptst@server2 "echo $APPHOME"
OR
server1> ssh apptst@server2 "ls -la"

Else, once login into server2 and check if this variable is really defined there or not,
Code:

server1> ssh apptst@server2
server2> echo $APPHOME


p2006.prashant 03-16-2013 01:21 AM

did you try using exec?

TB0ne 03-16-2013 09:02 AM

Quote:

Originally Posted by p2006.prashant (Post 4912697)
did you try using exec?

Why would you bother with exec, when ssh can already execute a command on a remote server on its own?

yowi 03-16-2013 07:25 PM

First, use single quotes around the command to protect the variable from local substitution.
Second, check the environment section of the ssh man page and the invocation section of the bash man page to be sure of how the remote environment is being set.

donls 03-19-2013 04:42 PM

Could use the 'env' command
 
Invoke env on local server and see what returns. Invoke on remote host and compare the two. The variable in question "should" match on both instances. If it doesn't show on remote invocation (but does on local), that would explain the discrepancy.

This removes any question about single/double quote interpretation.

kumarjohn 03-20-2013 02:22 AM

Hi,

I apologize for the delayed response.

Thanks all for your inputs.


@allend, $APPHOME is defined on server2 itself. There is no $APPHOME defined on server1. Tried with single quote but no luck.

@shivaa,

Quote:

server1> ssh apptst@server2 "echo $APPHOME"
When tried above command its a blank output.


Quote:

server1> ssh apptst@server2 "ls -la"
When tried the above command its returning the list of files and directories in $APPHOME path on server2.

Code:

server1> ssh apptst@server2
server2> echo $APPHOME

its retuning /app/home.

@p2006.prashant, as per @TB0ne the work is being done using ssh then why we need to check with exec. want to stick with ssh only.

@yowi, tired many combinations single, double quotes nothing works.


@donls, do you want me to enable env in sshd_config on both the server1 and sever2. the question is its just not working when doing echo. but it works when trying with ls or cd or mkdir. confused.

Best Regards,
KJ.

donls 03-20-2013 03:47 AM

Quote:

Originally Posted by kumarjohn (Post 4914970)
@donls, do you want me to enable env in sshd_config on both the server1 and sever2. the question is its just not working when doing echo. but it works when trying with ls or cd or mkdir. confused.

Issue env as a command:

Code:

$ env
LESSKEY=/etc/lesskey.bin
NNTPSERVER=news
MANPATH=/usr/local/man:/usr/share/man

...

[about 58 lines total]

OLDPWD=/home/omniadmin
_=/usr/bin/env

$

This will show all the ENV variables and some other stuff as well, telling you just what has been exported etc. If the value in question shows up, that confirms it should be there and is ready to use (did you export it?).

The set command also shows some interesting info, but env is what we want this time.

shivaa 03-20-2013 05:13 AM

There's difference between output of:
Code:

server1~$ ssh apptst@server2 "echo $APPHOME"
And,
Code:

server1~$ ssh apptst@server2
server2~$ echo $APPHOME

Therefore, the problem is all about how you quote the command parsed to ssh. Correct one is that with single quotes around the cmd, as:
Code:

server1~$ ssh apptst@server2 'echo $APPHOME'
OR
server1~$ ssh apptst@server2 'echo "$APPHOME"'


yowi 03-20-2013 11:06 AM

In which file are you declaring APPHOME?


All times are GMT -5. The time now is 12:09 AM.