So the following doesn’t do anything except illustrate how I worked around BASH not support multidimensional arrays.

In my production code (not the below example) I used the below loop to call an expect script. The expect script does the work of logging into the router(s). The output from expect is then piped to AWK, which handles the rest of the formatting.

I’m using a cron job to call up a bash script, which calls up an expect script, which hands the output data to AWK, which pipes it to a file on disk.

bash –> expect –> awk –> stout

# Not quite a multidimensional array
A=("" "")

echo '--------------------'
for ROW in ${A[*]}
   echo "processing row: $ROW"
   echo "HostAddress: ${ROW%:::*}"
   echo "Host Prompt: ${ROW#*:::}"

(Edited 1/5/2012)
The purpose for needing to associate a host name along with the IP address is to due to Expect.  When Expect logs into a device it is looking to match a prompt.  Not every device will have the exact same prompt so including a name (string) with the IP address helps in allowing a general/generic Expect script for all devices.

Last modified: 10/05/2021


Write a Reply or Comment