1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Simple Shell Script Help

Discussion in 'HTML, Graphics & Programming' started by skiba, 24 May 2006.

  1. skiba

    Mobster

    Joined: 27 Aug 2004

    Posts: 2,955

    Location: Singapore ExPat

    Hey guys, I need a hand with a simple shell script (bash). I have a file that contains a list of servers each on a separate line, what I want to do is use each hostname as a variable to log into, create a directory, exit and repeat. Now I gather I probably need to use a while loop or for loop but am not sure of the correct way to get the hostnames into an array? Do I need to cat it?
    Any pointers much appreciated.
     
  2. ByteJuggler

    Hitman

    Joined: 5 Jun 2005

    Posts: 987

    Location: Leicestershire

    Given a file words.txt containing
    the following command:

    Code:
    for word  in $(cat words.txt); do echo "word is: $word" ; done
    will produce the following output:

    So you probably want

    Code:
    for dir  in $(cat dirs.txt); do mkdir $dir ; done 
    (Well, you need to sort out the login bits of course........ )

    Hope that helps.
     
    Last edited: 25 May 2006
  3. skiba

    Mobster

    Joined: 27 Aug 2004

    Posts: 2,955

    Location: Singapore ExPat

    excellent thanks, will have a "bash" at this :D