I was wondering if there is a way to write to /etc/hosts file an entry by doing the following using a bash script (.sh)
- Get the ip of a host command for e.g. (could be any URL)
host cloud.com
- The reslt would be as follows:
cloud.com has address 50.17.245.212
- Finally, I want to insert into the /etc/hosts file the following:
50.17.245.212 ip-50-17-245-212
Note: First IP is of the URL and then followed by that it is prefixed with -ip and then dots are replaced with "-"
I tried with dig but the result is long, would appreciate any pointers here.