How to nslookup a fqdn and append the resulted IP to a line in a file

Viewed 36

I need to get current ip address of a fqdn and then add that IP in a config file after some other IPs. e.g IP1, IP2, IP3(ip obtained via nslookup)

IP1 and IP2 remain the same but IP3 will need to be updated if different than previous result.

So far I can get the nslookup result correctly as:

nslookup mywebsite.com | grep "Address" | awk '{print $3}' | sed -n 2p

The line in the file called "cofig", that needs updated looks like:

option allowed_ips '10.0.0.0/24, 10.0.2.0/24, IP3/32'

I am having trouble with replacing IP3 with the result from nslookup, keeping the /32 after that.

0 Answers
Related