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

  • A Plague For All Seasons

    Vainly valuing endless inefficacious toil seeds seemingly insatiable ennui Lifetimes of vague frustrations passed down from generation to generation…

  • NVMe on ESXi

    I am running ESXi 6.7u3 on an old PowerEdge R610 and recently purchased a no-name NVMe m.2 drive and the StarTech.com M2 PCIe SSD Adapter from…

  • Twin Lens Reflex

  • 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