Sponsored Content
Top Forums Shell Programming and Scripting Iterate array using loop over ssh Post 302831899 by mharald on Friday 12th of July 2013 07:32:56 AM
Old 07-12-2013
Quote:
Originally Posted by rajamadhavan
I think, this is expected.

When your commands go to server, all the variables are replaced by its values.
The 'echo '${test1[$m]}' at the end of your command is evaluated by your local system (the first element of the array since it cannot make out what $m is) and would be replaced by 'test1' by the time it reaches the server . So it prints the same for all the iterations.

Yes, makes sense (now that you mention it Smilie)

But that's the nice thing about BASH, there's no "No way out" problem:

Code:
#!/bin/bash
TEST=test
TEST1=(test1 test2 test3)
ssh server 'TEST2=('${TEST1[*]}') ; for m in $(seq 0 $(eval echo \${TEST2[*]} | tr " " "\n" | wc -l)); eval echo \${TEST2[$m]}; done'

Declaring a Variable, that is iterated before the loop, so that the array gets populated as expected and then iterated together with the loop variable $m.

Thank you for the hint. A nice day to you all Smilie
This User Gave Thanks to mharald For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

iterate over array

I can not for the life of me figure out how to iterate over this array { 'name1' => { 'a' => . 'b' => }, 'name2' => { 'a' => . 'b' => } } I want a for loop to iterate through the first element (name1 and name2 in my example) but I can't figure it out. Help... (2 Replies)
Discussion started by: IMTheNachoMan
2 Replies

2. Shell Programming and Scripting

How to loop(Iterate) through List with foreach(csh)

Hey all,, I know cshell is harmful:) but I am using this just "to know" - for educational purposes!... not for a long-term use. lets say i have a list.. set arr=(x y z e f) I wanna iterate the list with foreach ,, not with while.!! foreach i $arr echo $i end does not work (2 Replies)
Discussion started by: eawedat
2 Replies

3. Shell Programming and Scripting

Array with do while and if loop

Hi All, I am trying to run a do while for an array. And in the do while, I'm trying to get a user response. Depending on the the answer, I go ahead and do something or I move on to next element in the array. So far I can read the array, but I can't get the if statement to work. Any suggestions... (5 Replies)
Discussion started by: nitin
5 Replies

4. UNIX for Dummies Questions & Answers

Iterate/Loop Through XML Node List

I need to load an XML file and loop through a list of nodes in it to execute a shell script for each one using the attributes for each node as parameters for the script. Any ideas? Any help will be much appreciated. (1 Reply)
Discussion started by: bradlecat
1 Replies

5. Shell Programming and Scripting

Array Variable being Assigned Values in Loop, But Gone when Loop Completes???

Hello All, Maybe I'm Missing something here but I have NOOO idea what the heck is going on with this....? I have a Variable that contains a PATTERN of what I'm considering "Illegal Characters". So what I'm doing is looping through a string containing some of these "Illegal Characters". Now... (5 Replies)
Discussion started by: mrm5102
5 Replies

6. Shell Programming and Scripting

Do loop doesn't iterate

I'm trying to send the file list as parameter to another job and execute it. But the loop doesn't work, the inner job is running only once and not twice as expected for filelist in $(ls -rt *.txt | tail -2) do echo $filelist export filelist cmd="$Program -config $configfile -autoexec... (11 Replies)
Discussion started by: asandy1234
11 Replies

7. Shell Programming and Scripting

Ssh to an array of servers in a for loop

There are 4 remote hosts that I have stored in an array. A ssh trust has been created from the local host to each of the remote hosts. I am trying to ssh to each of the servers in a for loop as shown below. declare -a host host}]="server1" host}]="server2" host}]="server3" ... (9 Replies)
Discussion started by: Sree10
9 Replies

8. Shell Programming and Scripting

awk loop using array:wish to store array values from loop for use outside loop

Here's my code: awk -F '' 'NR==FNR { if (/time/ && $5>10) A=$2" "$3":"$4":"($5-01) else if (/time/ && $5<01) A=$2" "$3":"$4-01":"(59-$5) else if (/time/ && $5<=10) A=$2" "$3":"$4":0"($5-01) else if (/close/) { B=0 n1=n2; ... (2 Replies)
Discussion started by: klane
2 Replies

9. Shell Programming and Scripting

Using nested for loop to iterate over file names

I'm trying to grab a list of file names from a directory, then process those files 5 at a time. In the link below. Instead of using files I'm using the files array which contains 15 strings starting with AAA. So I'm trying to assign $fileset 5 of the strings at a time to pass to a command. So... (4 Replies)
Discussion started by: zBernie
4 Replies

10. Shell Programming and Scripting

Bash for loop array

Hi there, A bit new to bash and am having an issue with a for loop. I look for filenames in a specified directory and pull the date string from each meeting a certain criteria, and then would like to make a directory for each date found, like this: search 20180101.gz 20180102.gz 20180103.gz... (5 Replies)
Discussion started by: mwheeler12
5 Replies
CGEXEC(1)							 libcgroup Manual							 CGEXEC(1)

NAME
cgexec - run the task in given control groups SYNOPSIS
cgexec [-h] [-g <controllers>:<path>] [--sticky] command [arguments] DESCRIPTION
The cgexec program executes the task command with arguments arguments in the given control groups. -g <controllers>:<path> defines the control groups in which the task will be run. controllers is a list of controllers and path is the relative path to control groups in the given controllers list. This flag can be used multiple times to define multiple pairs of lists of controllers and relative paths. Instead of the list of all mounted controllers, the wildcard b"*b" can be used. If this option is not used, cgexec will automatically place the task in the right cgroup based on /etc/cgrules.conf. -h, --help Display this help and exit. --sticky If running the task command with this option, the daemon of service cgred (cgrulesengd process) does not change both the task of the command and the child tasks. Without this option, the daemon does not change the task of the command but it changes the child tasks to the right cgroup based on /etc/cgrules.conf automatically. EXAMPLES
cgexec -g *:test1 ls runs command ls in control group test1 in all mounted controllers. cgexec -g cpu,memory:test1 ls -l runs command ls -l in control group test1 in controllers cpu and memory. cgexec -g cpu,memory:test1 -g swap:test2 ls -l runs command ls -l in control group test1 in controllers cpu and memory and control group test2 in controller swap. FILES
/etc/cgrules.conf default libcgroup configuration file SEE ALSO
cgrules.conf (5) Linux 2009-03-15 CGEXEC(1)
All times are GMT -4. The time now is 08:03 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy