Extracting data from multiple variable sized arrays in bash onto one line -


i writing small bash script find mx records of given domain, print out hostname, ip address, , reverse address ip address. able store each hostname, ip, , reverse address 3 arrays:

$mxhosts[@] $mxips[@] $mxrhost[@] 

each contains same number of values, , depend on how many mx records domain has. want do, print out line data 3 arrays, number of values in arrays.

how able either a. create new array condenses 3 arrays 1 data or b. print out data 3 arrays using echo?

examples:

$mxhosts[0] = aspmx.l.google.com. $mxips[0] = 74.125.129.27 $mxrhost[0] = ia-in-f27.1e100.net. 

from that, i'd print out this:

aspmx.l.google.com. :: 74.125.129.27 :: ia-in-f27.1e100.net.

for each mx record, run this:

[~/scripts]# ./whomails google.com aspmx.l.google.com. :: 74.125.129.27 :: ia-in-f27.1e100.net. alt1.aspmx.l.google.com. :: 74.125.129.27 :: qe-in-f27.1e100.net. 

etc..

so far i've tried few different methods, using loops, if domain has multiple mx records print out possible combinations. 1 mx, works fine.

currently using following, gives me possible combinations:

for hosts in "${mxhosts[@]}";     ips in "${mxips[@]}";         rhosts in "${mxrhosts[@]}";             echo "$hosts :: $ips :: $rhosts"         done     done done 

how print corresponding array value, [1-n] instead of [@]*[@]*[@]?

i'm not sure if got want, if arrays have same size, may index them integer:

for (( = 0; < ${#array1[@]}; ++i ));     ${array1[$i]}     ${array2[$i]}     ...     ${arrayn[$i]} done 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -