I'm quite new at bash and I am trying to learn it by creating some small scripts.
I created a small script to look up the DNS entry for multiple domains at the same time. The domains are given as attributes.
COUNTER=0
DOMAINS=()
for domain in "$@"
do
WOUT_WWW=$(dig "$domain" +short)
if (( $(grep -c . <<<"$WOUT_WWW") > 1 )); then WOUT_WWW="${WOUT_WWW##*$'\n'}" ; fi
WITH_WWW=$(dig "www.${domain}" +short)
if (( $(grep -c . <<<"$WITH_WWW") > 1 )); then WITH_WWW="${WITH_WWW##*$'\n'}" ; fi
DOMAINS[$COUNTER]="$domain|$WOUT_WWW|$WITH_WWW"
COUNTER=$(($COUNTER+1))
done
Now I just want to loop through the new "multidimensional" array and give the output like mysql table:
+------------------------------+
| Row 1 | Row 2 | Row 3 |
+------------------------------+
| Value | Value | Value |
+------------------------------+
How can I do that?
dig
commands may contain multiple lines (likedig www,google.com +short
). Do you want to support that? – Stéphane Chazelas Sep 21 '16 at 12:14