running command remotely to populate local variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting running command remotely to populate local variable
# 1  
Old 11-19-2008
running command remotely to populate local variable

If I run this

Code:
[root@central-server] # ssh remote-server 'du -sk /usr/platform/`uname -i`/'
174     /usr/platform/SUNW,Sun-Fire-V245

I get my output just fine,

However, if i try to do the same but populate a local variable within my script called for example 'result'

Code:
#!/bin/ksh

result=`ssh remote-server 'du -sk /usr/platform/`uname -i`/'`
echo $result

I get

Code:
[root@central-server] # ./test.sh 
./test.sh[13]: /: cannot execute
./test.sh[13]: -i:  not found

It looks like the `uname -i` is not getting run remotely, does anybody know how I can get this to be recognised by the remote box ?

Any help would be great

Cheers
# 2  
Old 11-19-2008
Use proper korn shell command substitution in the script.
Code:
# cat script
     #!/usr/bin/ksh
     result=$(ssh remote-client 'du -sk /usr/platform/`uname -i`')
     echo $result

# ./script
448 /usr/platform/FJSV,GPUZC-M
#


Last edited by System Shock; 11-20-2008 at 10:59 AM..
# 3  
Old 11-19-2008
thankyou, i didnt know you could do that with the brackets ....is that ksh only ?

ps - works perfectly thanks
# 4  
Old 11-20-2008
It probably works in bash and newer shells as well.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Running local script remotely with arguments

Dear Experts, I have found this script on internet that can be used to execute local script remotely #!/bin/bash # runremote.sh # usage: runremote.sh localscript remoteuser remotehost arg1 arg2 ... realscript=$1 user=$2 host=$3 shift 3 # escape the arguments declare -a args ... (4 Replies)
Discussion started by: mukulverma2408
4 Replies

2. Red Hat

Can C program put message to IBM MQ remotely, if local server doesn't have MQ library?

Can somebody know if it is possible to connect to remote IBM MQ, if local server using C, but don't have MQ library? Thanks for contribution (0 Replies)
Discussion started by: digioleg54
0 Replies

3. Shell Programming and Scripting

Running local script remotely with arguments in ksh

When i use ssh command to execute local script on remote server , I am unable to do it. Please let me know how this can be done in ksh req=abc dte=ghd ssh username@hostname "$req $dte" < run_script.sh (2 Replies)
Discussion started by: lalitpct
2 Replies

4. Shell Programming and Scripting

populate a bash variable from an awk operation

Hi, I'm trying to populate bash script variable, data_size with the size of the largest file in my current directory data_size=$(ls -lS | grep -v "total" | head -1) | awk '{ print $5 }' I've tried adding an echo before the call to awk data_size=$(ls -l | grep -v "total" | head -1) |... (2 Replies)
Discussion started by: mark_s_g
2 Replies

5. Solaris

Can i bind to a local login terminal running using rsh or remotely

Hi Can i ask? I had multiple solaris workstation running and some local users using it. Is it possible to bind to the local user terminal or console he's using as if like the user well type and I can see it and what my typing in the local user see it also. Is it possible.. Thanks. (3 Replies)
Discussion started by: jao_madn
3 Replies

6. Shell Programming and Scripting

PHP populate variable with function

Hi, I've a php scirpt that calls in an external class. The external class, myClass, has several public and private functions. There is one public function which derives a value that I want be able to bring it to the main php scirpt. Here is the code. ....snip.... include... (1 Reply)
Discussion started by: nitin
1 Replies

7. Shell Programming and Scripting

remotely call function from local script

The following code doesn't work properly which means it doesn't displays remote output. #!/bin/ksh #################### Function macAddressFinder ######################## macAddressFinder() { `ifconfig -a > ipInterfaces` `cat ipInterfaces` }... (2 Replies)
Discussion started by: presul
2 Replies

8. UNIX for Advanced & Expert Users

mount CD from local laptop to UNIX server remotely

I need some help in emergency. I want to add some software package from Solaris 10 CD remotely to UNIX Sparc machine. I can remotely access into the machine. Question is: how do I insert Solaris 10 CD in my laptop, then mount to UNIX machine remotely and add software package. Please give me the... (7 Replies)
Discussion started by: duke0001
7 Replies

9. Shell Programming and Scripting

populate variable from remote result

Hi there i am trying to pass the result of a remote command into a variable into my script ie #!/bin/sh var = `ssh remote_box 'uname'` echo $var but all i get back is ./script.sh: var: not found However when i add a -x to put it into diag mode i get the following + ssh... (2 Replies)
Discussion started by: hcclnoodles
2 Replies
Login or Register to Ask a Question