ehowton (ehowton) wrote,
ehowton
ehowton

Query a List of Hostnames to Create /etc/hosts File

for x in `cat hostnames`;
do echo $(nslookup $x | grep -e Address | sed -n 2p | sed -r 's/.{9}//') $x ;
done >> hostfile

Or, add SHORTNAME and ALIAS:

for x in `cat hostnames`;
do echo $(nslookup $x | grep -e Address | sed -n 2p | sed -r 's/.{9}//') $x $(echo $x | sed "s/\..*//") $(echo $x | sed "s/\..*//").alt.fqdn;
done >> hostfile
Tags: linux, unix
Subscribe

  • Game Face

    I awoke after a blissful 10-hour slumber, ensconced in my flannel cocoon on an unseasonably cool morning. I tucked my arms close, pulling the…

  • Indian Burial Ground

    Its been two years we've been in this house. Two excruciating years atop a deeply buried curse, due to the imagined Indian burial ground mere feet…

  • Speaking of Old School

  • Post a new comment

    Error

    default userpic

    Your IP address will be recorded 

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.
  • 0 comments