-2

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

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

1 Answer 1

1

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
  • 3
    copy and paste text, don't post screenshots.
    – cas
    Dec 2, 2015 at 8:44
  • @cas that from a fresh VM , tools not yet installed.
    – Raja G
    Dec 2, 2015 at 8:44
  • @Raja If, instead "$host" I write www.example.com, it all works...
    – J.Doy
    Dec 2, 2015 at 9:11

Not the answer you're looking for? Browse other questions tagged .