-2

This question already has an answer here:

I write script, but this does not work. I need the script, which will take IP from the file etc/hosts. How to do it?

Script: (This does not work)

host=www.example.com

ip=$(getent hosts "$host" | awk '{ print $1}')

echo $ip

marked as duplicate by jasonwryan, cas, John1024, Archemar, Scott Dec 2 '15 at 9:07

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 2
    posting the exact same question again won't get you different answers. – cas Dec 2 '15 at 8:44
  • Voting to delete this because it's the same question posted by the same user. – roaima Dec 7 '15 at 23:33
0

If your given hostname at host filed is able to get name resolution then for sure you will get output.

Check are you able to ping to given hostname or not.

enter image description here

  • 3
    copy and paste text, don't post screenshots. – cas Dec 2 '15 at 8:44
  • @cas that from a fresh VM , tools not yet installed. – rɑːdʒɑ Dec 2 '15 at 8:44
  • @Raja If, instead "$host" I write www.example.com, it all works... – J.Doy Dec 2 '15 at 9:11

Not the answer you're looking for? Browse other questions tagged or ask your own question.