Find the answer to your Linux question:
Results 1 to 3 of 3
Hi, I have been looking around for a good tutorial when using "for" i would like to use it to use a list of hostname "hosts.txt" and have it go ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Sep 2008
    Posts
    5

    Question using for command to resolve list of hostname to ip


    Hi,

    I have been looking around for a good tutorial when using "for"

    i would like to use it to use a list of hostname "hosts.txt" and have it go through the list, using "host <server.my.com> and then output the data to a file.

    any hints on how to correctly get this working for me is appreciated.

    i was hoping to use:

    for variable in hosts.txt
    do
    host
    done

    how doe the variable get defined though? and is this the proper way? : )

    thanks!

    my hosts.txt file is basically:

    server1.my.com
    server2.my.com
    etc...

  2. #2
    Trusted Penguin Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    3,221
    Code:
    for NODE in $(cat hosts.txt); do host ${NODE};done
    You must always face the curtain with a bow.

  3. #3
    Trusted Penguin Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    3,221
    If hosts.txt contains a large amount of hosts, then you might want to replace the for loop with parallel: Build and execute shell command lines from standard input in parallel
    You must always face the curtain with a bow.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •