Sponsored Content
Top Forums Shell Programming and Scripting Iterate array using loop over ssh Post 302832003 by Corona688 on Friday 12th of July 2013 12:02:18 PM
Old 07-12-2013
Another way around the variable problem, a particularly robust one, is this:

Code:
ssh username@host /bin/sh -s arg1 arg2 arg3 <<"EOF"
literal script contents
that don't even need
extra quotes
or escaping
EOF

Also, "${ARRAY[@]}" is a safer way to expand an array, because it splits upon elements, not spaces. It works for commandline arguments too. Also, your loop can be simplified quite a lot. How about this:

Code:
ssh username@host /bin/sh -s "${TEST1[@]}" <<"EOF"
echo "$@"
echo "${1}"

N=0
for m in "$@" # Expands into $1 $2 $3 ...
do
        echo $m
        echo $N
        let N=N+1
done
EOF


Last edited by Corona688; 07-12-2013 at 01:10 PM..
 

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
KTR(9)							   BSD Kernel Developer's Manual						    KTR(9)

NAME
CTR0, CTR1, CTR2, CTR3, CTR4, CTR5 -- kernel tracing facility SYNOPSIS
#include <sys/param.h> #include <sys/ktr.h> extern int ktr_cpumask; extern int ktr_entries; extern int ktr_extend; extern int ktr_mask; extern int ktr_verbose; extern struct ktr_entry ktr_buf[]; void CTR0(u_int mask, char *format); void CTR1(u_int mask, char *format, arg1); void CTR2(u_int mask, char *format, arg1, arg2); void CTR3(u_int mask, char *format, arg1, arg2, arg3); void CTR4(u_int mask, char *format, arg1, arg2, arg3, arg4); void CTR5(u_int mask, char *format, arg1, arg2, arg3, arg4, arg5); void CTR6(u_int mask, char *format, arg1, arg2, arg3, arg4, arg5, arg6); DESCRIPTION
KTR provides a circular buffer of events that can be logged in a printf(9) style fashion. These events can then be dumped with ddb(4), gdb(1) or ktrdump(8). Events are created and logged in the kernel via the CTRx macros. The first parameter is a mask of event types (KTR_*) defined in <sys/ktr.h>. The event will be logged only if any of the event types specified in mask are enabled in the global event mask stored in ktr_mask. The format argument is a printf(9) style format string used to build the text of the event log message. Following the format string are zero to five arguments referenced by format. Each event is logged with a file name and source line number of the originating CTR call, and a timestamp in addition to the log message. The event is stored in the circular buffer with supplied arguments as is, and formatting is done at the dump time. Do not use pointers to the objects with limited lifetime, for instance, strings, because the pointer may become invalid when buffer is printed. Note that the different macros differ only in the number of arguments each one takes, as indicated by its name. The ktr_entries variable contains the number of entries in the ktr_buf array. These variables are mostly useful for post-mortem crash dump tools to locate the base of the circular trace buffer and its length. The ktr_mask variable contains the run time mask of events to log. The CPU event mask is stored in the ktr_cpumask variable. The ktr_verbose variable stores the verbose flag that controls whether events are logged to the console in addition to the event buffer. EXAMPLES
This example demonstrates the use of tracepoints at the KTR_PROC logging level. void mi_switch() { ... /* * Pick a new current process and record its start time. */ ... CTR3(KTR_PROC, "mi_switch: old proc %p (pid %d)", p, p->p_pid); ... cpu_switch(); ... CTR3(KTR_PROC, "mi_switch: new proc %p (pid %d)", p, p->p_pid); ... } SEE ALSO
ktr(4), ktrdump(8) HISTORY
The KTR kernel tracing facility first appeared in BSD/OS 3.0 and was imported into FreeBSD 5.0. BUGS
Currently there is one global buffer shared among all CPUs. It might be profitable at some point in time to use per-CPU buffers instead so that if one CPU halts or starts spinning, then the log messages it emitted just prior to halting or spinning will not be drowned out by events from the other CPUs. The arguments given in CTRx() macros are stored as u_long, so do not pass arguments larger than size of an u_long type. For example passing 64bit arguments on 32bit architectures will give incorrect results. BSD
November 30, 2008 BSD
All times are GMT -4. The time now is 06:35 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy