Вот несколько способов выполнить nslookup в цикле для этих хостов:
Способ 1 - через массив:
#!/bin/bash
hosts=(
"marketplace-remote-wh-events-kafka-1.dp.wb.ru"
"marketplace-remote-wh-events-kafka-1.el.wb.ru"
"marketplace-remote-wh-events-kafka-1.dl.wb.ru"
"marketplace-remote-wh-events-kafka-2.el.wb.ru"
"marketplace-remote-wh-events-kafka-2.dl.wb.ru"
)
for host in "${hosts[@]}"; do
echo "=== Checking $host ==="
nslookup "$host"
echo
done
Способ 2 - через строку с разделителями:
#!/bin/bash
hosts="marketplace-remote-wh-events-kafka-1.dp.wb.ru,marketplace-remote-wh-events-kafka-1.el.wb.ru,marketplace-remote-wh-events-kafka-1.dl.wb.ru,marketplace-remote-wh-events-kafka-2.el.wb.ru,marketplace-remote-wh-events-kafka-2.dl.wb.ru"
IFS=',' read -ra HOST_ARRAY <<< "$hosts"
for host in "${HOST_ARRAY[@]}"; do
echo "=== Checking $host ==="
nslookup "$host"
echo
done
Способ 3 - однострочник:
for host in marketplace-remote-wh-events-kafka-1.dp.wb.ru marketplace-remote-wh-events-kafka-1.el.wb.ru marketplace-remote-wh-events-kafka-1.dl.wb.ru marketplace-remote-wh-events-kafka-2.el.wb.ru marketplace-remote-wh-events-kafka-2.dl.wb.ru; do echo "=== $host ==="; nslookup "$host"; echo; done
Способ 4 - с обработкой ошибок:
#!/bin/bash
hosts=(
"marketplace-remote-wh-events-kafka-1.dp.wb.ru"
"marketplace-remote-wh-events-kafka-1.el.wb.ru"
"marketplace-remote-wh-events-kafka-1.dl.wb.ru"
"marketplace-remote-wh-events-kafka-2.el.wb.ru"
"marketplace-remote-wh-events-kafka-2.dl.wb.ru"
)
for host in "${hosts[@]}"; do
echo "=== Checking $host ==="
if nslookup "$host" > /dev/null 2>&1; then
nslookup "$host"
echo "✓ Success"
else
echo "✗ Failed to resolve $host"
fi
echo
done
Рекомендую использовать первый способ - он наиболее читаемый и удобный для модификации.