Not quite a multidimensional array (hack)

Posted by

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.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.