Retrive the value returned by a command excuted in a remote server using ssh


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Retrive the value returned by a command excuted in a remote server using ssh
# 1  
Old 10-08-2008
Retrive the value returned by a command excuted in a remote server using ssh

Hello Everybody,

I'm facing a weird problem with the awk command.

I try to retrieve in a variable the value returned by a simple ls command.
ls /export/home/tmp |tail -1 return a good value (the name of the .
But When I try to execute the same command in a remote server using ssh as follows:
ssh root@192.168.1.20 "TERM=xterm; export TERM; VAR=`ls /export/home/tmp |tail -1`; echo $VAR"
I have the following error message:
ls: cannot access /export/home/tmp: No such file or directorySmilie

Could someone help me to resolve this problem by storing the retuned valu in a variable.

Thanx a lot!!
# 2  
Old 10-08-2008
This doesn't work that way; see why with this example:

Code:
root@somehost:/> a=3
root@somehost:/> ssh isau02 "a=1; echo $a"
3

The variable is read in your current shell, not the remote shell. Maybe use it this way:
Code:
root@somehost:/> A=`ssh isau02 "ls -1| tail -1"`
root@somehost:/> echo $A
xorg.conf.new

# 3  
Old 10-08-2008
Hi Zaxxon,

Thanx a lot for your help.

Cheers.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Multi server access through remote server using ssh

Team, Presently I have 5 ip address kept in ip_abc1 file, for each of the ip address listed, i need to login on each ipaddress one at a time and login as below for that specific ip address ssh -p 8101 karaf@<ip.address_for the specific ip address as logged in> password features:list... (4 Replies)
Discussion started by: whizkidash
4 Replies

2. UNIX for Advanced & Expert Users

Unable to ssh to remote server

Hi, I have two SunOs sparc servers mac1 and mac2. I have exchanged keys between them inorder to passwordless login ssh from mac1 to mac2. However, it is failing after authentication. Part of the debug is as below. Please suggest whats wrong and how do i fix that!! Note: i do not have... (1 Reply)
Discussion started by: mohtashims
1 Replies

3. Shell Programming and Scripting

Script to ssh to remote server

Hi All, I need to prepare a script. Description: Currently i am in server "x(ubuntu os)", here i need to develop a script to ssh to another server "y(ubuntu os)", i have password less authentication to "y". i have done the below #!/bin/bash #ssh to the server "y" and confirming i am... (2 Replies)
Discussion started by: kumar85shiv
2 Replies

4. Shell Programming and Scripting

Ssh to remote server loop is breaking

hi All, cat login.list server1 userid1 server2 userid2 server3 userid3 ---------------------------------------- #SSHSCRIPT.ksh FILE=login.list while read vah vah_id do ssh $vah -l $vah_id "pwd" done < "$FILE" ----------------------------------------- When i... (2 Replies)
Discussion started by: raghur77
2 Replies

5. Shell Programming and Scripting

Need to stop script for until present command excuted

Hi, Basically I am running a script in another script. #!/bin/sh DIRECTORY="/export/home/scripts" CURDATIME=`date '+%m%d%y_%H%M%S'` LOG_FILE="${DIRECTORY}/${CURDATIME}_abc.out" echo "ABC Delta Script started at `${CURDATIME}`" > $LOG_FILE cd ${DIRECTORY} sh ./abcDeltaRun.sh >>... (1 Reply)
Discussion started by: tnrchinna
1 Replies

6. UNIX for Dummies Questions & Answers

Long listing of files using find command on remote server via SSH

Hi , I am trying to find some files on a remote machine using the find command. >ssh -q atukuri@remotehostname find /home/atukuri/ -name abc.txt /home/atukuri/abc.txt The above command works fine and lists the file, but if I want to do a long listing of files (ls -l) its not working . ... (2 Replies)
Discussion started by: atukuri
2 Replies

7. UNIX for Dummies Questions & Answers

Is it possible for a server to be both a remote and client SSH host?

Hi, Not sure if this is possible, I have a server (SERVER1) that is currently set up as a remote SSH host. My client SSH host (SERVER2) is connecting to SERVER1 to scp a file with no password. I now have a need to set up a third server (SERVER3) as a remote SSH host and I need SERVER1 as a... (4 Replies)
Discussion started by: tatchel
4 Replies

8. Shell Programming and Scripting

SSH Remote Server issue

I have a script that connects to remote servers using a public key. Some of the servers are not set up for the public key and I receive the following when I attempt to ssh: The authenticity of host 'XXX' can't be established. RSA key fingerprint is... (1 Reply)
Discussion started by: la_womn
1 Replies

9. HP-UX

returned from remote command

Hi, there, I want to excute the remote command shell via "remsh", are there any simple or best way to get the result of remote shell from local ? thanks. (2 Replies)
Discussion started by: Frank2004
2 Replies
Login or Register to Ask a Question