The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Array inside an array manas_ranjan UNIX for Advanced & Expert Users 5 06-10-2008 03:25 PM
Problem inside 'if' ayankm Shell Programming and Scripting 1 09-12-2007 09:01 AM
formatting textfile inside ksh script using awk not working tekline UNIX for Advanced & Expert Users 6 07-03-2007 02:40 AM
inside the JVM rein UNIX for Advanced & Expert Users 1 08-05-2005 02:57 PM
pipes inside pranki High Level Programming 13 04-10-2005 11:41 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-06-2006
reldb reldb is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 19
Question looping a array inside inside ssh is not working, pls help

set -A arr a1 a2 a3 a4
# START
ssh -xq $Server1 -l $Username /usr/bin/ksh <<-EOS

integer j=0
for loop in ${arr[*]}
do
printf "array - ${arr[$j]}\n"
(( j = j + 1 ))
j=`expr j+1`
done
EOS
# END



=========
this is not giving me correct output.
I just want to print a1 a2 a3 a4 a5 as per my variable j inside ssh
pls do let me know any solution using a variable

without a variable directly using a loop for array works fine in ssh and using a variable works fine without ssh but giving problem with ssh

i guess ineed to escape few chars which i am nt sure.

I'll appriciate if you can post any working dummy code
i tried all solution but nothng worked for me.


reldb
  #2 (permalink)  
Old 07-06-2006
System Shock's Avatar
System Shock System Shock is offline Forum Advisor  
Registered User
  
 

Join Date: May 2006
Location: Tau Ceti V
Posts: 521
... probably have to escape the $'s and ('s with \ 's
  #3 (permalink)  
Old 07-06-2006
reldb reldb is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 19
i tried to escape the $ with \ but still it didnt work

all the time either it gives error or print only 0th element even though j is 2 or 3
quite strange

any working code ?
  #4 (permalink)  
Old 07-07-2006
LivinFree's Avatar
LivinFree LivinFree is offline Forum Advisor  
Goober Extraordinaire
  
 

Join Date: Jul 2001
Location: Portland, OR, USA
Posts: 1,584
It's late for me, but at a glance, and without testing it myself, I'd say that you're declaring the "arr" array locally, then trying to gather the elements of it remotely.

Does this work?
Code:
# START
ssh -xq $Server1 -l $Username /usr/bin/ksh <<-EOS
set -A arr a1 a2 a3 a4
integer j=0
for loop in ${arr[*]}
do
printf "array - ${arr[$j]}\n"
(( j = j + 1 ))
j=`expr j+1`
done
EOS
# END
  #5 (permalink)  
Old 07-07-2006
reldb reldb is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 19
echo "above ssh=" ${arr[2]}
ssh -xq $Server1 -l $Username /usr/bin/ksh <<-EOS

for loop in ${arr[*]}
do
echo "1=" \$loop
echo "2=" \${arr[2]}
done

EOS


---
above ssh value is shown properly
echo 1 loop value is also shown properly
but echo 2= is coming as blank

i am not even using the variable.. the same ${arr[2]} is working before ssh but not working in ssh statements.

any idea guys?
  #6 (permalink)  
Old 07-07-2006
Corona688 Corona688 is offline
Registered User
  
 

Join Date: Aug 2005
Location: Saskatchewan
Posts: 1,937
Quote:
Originally Posted by reldb
i am not even using the variable.. the same ${arr[2]} is working before ssh but not working in ssh statements.
Um, yes, that you are using the variable means that you are, in fact, using the variable. That's what 'using' means. As macosta pointed out, variables don't carry across like that. if you don't declare and populate the array in the block for the ssh then it won't know what it is.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 02:17 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0