Resolve a hostname to IP in a bash script
bash run on Linux
HOW TO:
| In order to use this script, you need to make sure that nslookup has been installed: apt-get install dnsutils The bash script that resolves an IP from a hostname is: #!/bin/sh set `nslookup costia.gritto.net | grep Add | grep -v '#' | cut -f 2 -d ' '` echo $1 The following script uses a fancy combination of grep and cut to display solely the IP of the bubble.gritto.net hostname, which is resolved using nslookup. If you use the set `...` line in your script, you will be able to reference the desired IP anytime during your script by calling the variable: $1 ** Keep in mind that the ` in the set line are NOT single quotes, but are from pressing the button above TAB. |
Reference URL:
Submit a Comment:
We are sorry but we have had to suspend the commenting function due to mass amounts of spam congesting the system. Sorry for the inconvience.