Question: UNIX (CENTOS 6.6) Script question: Having trouble putting together the script for the question below, any help is appreciated. Create a script that will read

UNIX (CENTOS 6.6) Script question:

Having trouble putting together the script for the question below, any help is appreciated. Create a script that will read a file containing a list of IPs (let's say 7 IPs) and try to resolve the Fully Qualified Domain Name (FQDN) with the `host` command (it needs to use this command) (such as 8.8.8.8 with www.google.com). The script should store the IP and FQDN (or UNKNOWN if the IP cannot be resolved), one set per line, comma-separated, to a file named resolved.txt.

The below prints out a comma only:

#!/bin/bash #shebang statetement

file="./data.txt" #input file containing ip addresses

while IFS= read line #reading each line from input file

do

output= `host $line` #executing host command and storing the output in output

if [[ "$output" =~ "*not found*" ]]; then #validating whether domain name is resoved or not

echo "UNKNOWN," >> "resolved.txt" #storing into resolved.txt

else

echo "$output," >> "resolved.txt"

fi

done <"$file"

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!