looping a array inside inside ssh is not working, pls help


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting looping a array inside inside ssh is not working, pls help
# 1  
Old 07-06-2006
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  
Old 07-06-2006
... probably have to escape the $'s and ('s with \ 's
# 3  
Old 07-06-2006
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  
Old 07-07-2006
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  
Old 07-07-2006
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  
Old 07-07-2006
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Array initialization inside class in C++

const int VALUES = {7,4,2,1,0}; //or int VALUES = {7,4,2,1,0};this statement inside a class definition gives error. Why? (3 Replies)
Discussion started by: milhan
3 Replies

2. UNIX for Dummies Questions & Answers

Array inside sed

Hi guys Let me at first describe the whole thing that I'm trying to do. Lets say I have 100 files like the following one. Ow 1230 16.000000 -0.834000 16.083957 1.751652398 -17.20094528 -4.450623277 Hw 1231 ... (6 Replies)
Discussion started by: saleheen
6 Replies

3. Shell Programming and Scripting

How to use variable inside array?

I tried to use variable inside an array variable, but its not working as expected.:wall: ENV1=123 ENV1=789 ENV1=120 ENV2=567 if then name=ENV1 echo "${name}" echo "${name}" echo "${name}" else name=ENV1 echo "${name}" fi Output: ./val.sh 1 123 (2 Replies)
Discussion started by: Jayavinoth
2 Replies

4. Shell Programming and Scripting

Renumber position 88-94 inside all files matching criteria inside folder

There are 4 files inside one folder matching criteria i.e. File name = ABCJmdmfbsjopXXXXXXX_mm-dd-yyyy_XXX.data Here is the Code which find the files matching criteria:- TS=`date +"%m-%d-%Y"`| for fname in `find . -name "ABCJmdmfbsjop???????_${TS}*.data"` do # Matching File Processing Code.... (1 Reply)
Discussion started by: lancesunny
1 Replies

5. Shell Programming and Scripting

unique inside array

I have a file root@server # cat /root/list12 11.22.33.44 22.33.44.55 33.44.55.66 33.44.55.66 33.44.55.66 I try to pass to array and display unique. root@server# cat /root/test12.sh #!/bin/bash #delcare array badips and accumulate values to array elemenrs badips=( $( cat... (4 Replies)
Discussion started by: anil510
4 Replies

6. Shell Programming and Scripting

Calling array inside awk

Hello I have the file df.tmp FS is actually the / FS but escape character\ and end of line $ is used in order to fetch exctly / and not other filesystems. awk '/\/$/ {print $(NF-1)+0}' df.tmp will work properly and return a value eg. 60 but when I am trying to issue the command with the array... (3 Replies)
Discussion started by: drbiloukos
3 Replies

7. Shell Programming and Scripting

pls help with cat inside script

Hi, Am not very well versed with unix, i wrote a script which will make a new file using cat option like this, trans.sh #!/bin/sh cat > file1 echo how are you I wrote only this part since i want to use this concept for something else. What i want to ask is, this script when executed... (4 Replies)
Discussion started by: romsf
4 Replies

8. Shell Programming and Scripting

Using ssh to transfer file not working inside if-condition

Hi all, ssh uname@remote_server 'cat /tmp/remote_file_name > home_dir/a512386/new/local_file_name' The above given command is working fine. but if i try to move the file only if exists in the remote server i.e) giving the same within if condition it executes but the file is not stored in my... (1 Reply)
Discussion started by: Shri123
1 Replies

9. Shell Programming and Scripting

using array inside awk

Hi All, I have the following code sequence for reading some bulk file and moving the content to two different arrays. while read data do THREEG_PATTERN=`echo $data | egrep "3G"` if then NEW_THREEG_PATTERN=`echo $THREEG_PATTERN | cut -d " " -f2` ... (12 Replies)
Discussion started by: subin_bala
12 Replies

10. Shell Programming and Scripting

split and making an array inside another array

I want to run an awk split on a value that has been pushed through an array and I was wondering what the syntax should be?? e.g. running time strings through an array and trying to examine just minutes: 12:25:30 10:15:13 08:55:23 awk ' NR==FNR{ ... (2 Replies)
Discussion started by: dcfargo
2 Replies
Login or Register to Ask a Question