Saturday, April 27, 2024
 Popular · Latest · Hot · Upcoming
5
rated 0 times [  5] [ 0]  / answers: 1 / hits: 487  / 2 Years ago, tue, july 19, 2022, 3:09:35

How can I create a shell script which receives a vector argument like



./script.sh google.com,yahoo.com



and display ip for each domain



like google.com 100.23.123.13






EDIT:



#!/bin/bash

while [ "$1" ];
do
host $1 | grep address | head -1
done

More From » scripts

 Answers
6

You can use the following script:



#!/bin/sh

for domain in $@; do
host $domain | grep "has address" | awk '{print $1" "$4}'
done


Usage: ./script www.domain1.com domain2.com ...



For example:



$ ./script.sh www.google.com yahoo.com www.askubuntu.com google.ro
www.google.com 173.194.40.81
www.google.com 173.194.40.84
www.google.com 173.194.40.82
www.google.com 173.194.40.83
www.google.com 173.194.40.80
yahoo.com 98.138.253.109
yahoo.com 206.190.36.45
yahoo.com 98.139.183.24
askubuntu.com 198.252.206.24
google.ro 173.194.35.31
google.ro 173.194.35.23
google.ro 173.194.35.24

[#29441] Wednesday, July 20, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
donurp

Total Points: 328
Total Questions: 128
Total Answers: 123

Location: Faroe Islands
Member since Thu, Apr 8, 2021
3 Years ago
;