LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-15-2013, 09:19 AM   #1
kumarjohn
LQ Newbie
 
Registered: Oct 2012
Posts: 22

Rep: Reputation: Disabled
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.
 
Old 03-16-2013, 01:58 AM   #2
allend
Senior Member
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware-current
Posts: 4,429

Rep: Reputation: 1348Reputation: 1348Reputation: 1348Reputation: 1348Reputation: 1348Reputation: 1348Reputation: 1348Reputation: 1348Reputation: 1348Reputation: 1348
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
 
Old 03-16-2013, 02:06 AM   #3
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
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
 
Old 03-16-2013, 02:21 AM   #4
p2006.prashant
LQ Newbie
 
Registered: Dec 2007
Location: India
Distribution: Redhat Linux 5,6.2, Solaris
Posts: 16
Blog Entries: 1

Rep: Reputation: 5
did you try using exec?
 
Old 03-16-2013, 10:02 AM   #5
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 17,916

Rep: Reputation: 3689Reputation: 3689Reputation: 3689Reputation: 3689Reputation: 3689Reputation: 3689Reputation: 3689Reputation: 3689Reputation: 3689Reputation: 3689Reputation: 3689
Quote:
Originally Posted by p2006.prashant View Post
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?
 
Old 03-16-2013, 08:25 PM   #6
yowi
Member
 
Registered: Dec 2002
Location: Au
Distribution: Debian
Posts: 209

Rep: Reputation: 54
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.
 
Old 03-19-2013, 05:42 PM   #7
donls
LQ Newbie
 
Registered: May 2010
Posts: 10
Blog Entries: 1

Rep: Reputation: 0
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.
 
Old 03-20-2013, 03:22 AM   #8
kumarjohn
LQ Newbie
 
Registered: Oct 2012
Posts: 22

Original Poster
Rep: Reputation: Disabled
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.
 
Old 03-20-2013, 04:47 AM   #9
donls
LQ Newbie
 
Registered: May 2010
Posts: 10
Blog Entries: 1

Rep: Reputation: 0
Quote:
Originally Posted by kumarjohn View Post
@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.
 
Old 03-20-2013, 06:13 AM   #10
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
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"'
 
Old 03-20-2013, 12:06 PM   #11
yowi
Member
 
Registered: Dec 2002
Location: Au
Distribution: Debian
Posts: 209

Rep: Reputation: 54
In which file are you declaring APPHOME?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Ubuntu etc/profile: environmental variable doesn't display content greenpool Linux - Newbie 12 07-31-2011 10:03 AM
open webmail unable to retrive MailBox....Urgent Please..... farrukhndm Linux - Server 6 08-25-2008 08:02 AM
Add/Remove programs "unable to retrive system information" suresh060979 Fedora 2 11-10-2007 12:46 PM
Unable to retrive software information fireball003 Fedora 1 07-26-2006 06:44 AM
Unable to send or retrive file using vsftpd yspl Linux - Networking 4 09-29-2005 11:10 AM


All times are GMT -5. The time now is 06:31 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration