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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started