Find the answer to your Linux question:
Page 2 of 2 FirstFirst 1 2
Results 11 to 18 of 18
Originally Posted by kapuera Hi again, Paralel connection is not must. I have too many time, operation can take a long time, it's not problem. I will give a time ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #11
    ped
    ped is offline
    Just Joined!
    Join Date
    Jun 2005
    Posts
    4

    Quote Originally Posted by kapuera View Post
    Hi again,
    Paralel connection is not must. I have too many time, operation can take a long time, it's not problem.
    I will give a time out to ssh, 10 seconds timeout is a reason to next host.
    Textfile contains hosts, i will not create it. It's already created.
    Host don't need to restart.

    I will start a command on ssh with a ssh parameter. For example; i 'll create a text file on remote host. It's not complex operation.

    I only need to know how to give ip address to ssh command from a text file using shell script.

    It's important for me.

    Thanx for your helps.
    How about this, from a bash prompt:

    cat filewithIPs | while read host
    do
    ssh root@$host <command>
    sleep 10
    done

    That will process each host/IP one at a time from the prompt, doing whatever it is you need to do to each host with ssh.

  2. #12
    Just Joined!
    Join Date
    Jan 2011
    Location
    Dorset, UK
    Posts
    4
    Quote Originally Posted by ped View Post
    How about this, from a bash prompt:

    cat filewithIPs | while read host
    do
    ssh root@$host <command>
    sleep 10
    done

    That will process each host/IP one at a time from the prompt, doing whatever it is you need to do to each host with ssh.

    The problem with using 'shell' – ie bash to connect to a remote server is that it can not return back to the shell. So the example that Ped gave you wont work because the remote host is waiting for a return (\r) character or a line feed (\n) character. The concept is perfect but it will not work using shell.

    There are a number of ways of dong this. PERL is one way but its quite a task to 'interact'. The very best way which is easy to understand is tcl/expect. This was written by a guy called Don Libes for exactly the same type of task that you want to achieve – ie where you need to interact.

    If you are able to install 'tcl/expect 'on your system and you want to use this approach, then I can give you the information/examples that will perform your tasks.

  3. #13
    Just Joined!
    Join Date
    Jan 2011
    Location
    Dorset, UK
    Posts
    4
    Quote Originally Posted by kingn View Post
    The problem with using 'shell' – ie bash to connect to a remote server is that it can not return back to the shell. So the example that Ped gave you wont work because the remote host is waiting for a return (\r) character or a line feed (\n) character. The concept is perfect but it will not work using shell.

    There are a number of ways of dong this. PERL is one way but its quite a task to 'interact'. The very best way which is easy to understand is tcl/expect. This was written by a guy called Don Libes for exactly the same type of task that you want to achieve – ie where you need to interact.

    If you are able to install 'tcl/expect 'on your system and you want to use this approach, then I can give you the information/examples that will perform your tasks.

    Hi Again - Well I have just checked out pssh myself and I think its worth a look.

  4. #14
    ped
    ped is offline
    Just Joined!
    Join Date
    Jun 2005
    Posts
    4
    I think mine may work, with a slight modification.

    cat filewithIPs | while read host
    do
    ssh root@$host <<-EOF
    commands to execute on remote host go here...
    exit
    EOF
    sleep 10
    done

    In fact, I just tested it locally on my system and it worked.

  5. #15
    Linux Enthusiast
    Join Date
    Jan 2005
    Location
    Saint Paul, MN
    Posts
    629
    Quote Originally Posted by kapuera View Post
    Hi to all,
    I need to make an mass-ssh connection.
    I mean that;
    I have a text file that thousand IP addresses. I need to make ssh connection to this ip address one by one. I will create a text file each ssh server.

    Thanx for your help.
    You might want to look at "clusterssh" see SourceForge.net: clusterssh

  6. #16
    Just Joined!
    Join Date
    Jan 2011
    Location
    Dorset, UK
    Posts
    4

    It will work!!!

    Quote Originally Posted by ped View Post
    I think mine may work, with a slight modification.

    cat filewithIPs | while read host
    do
    ssh root@$host <<-EOF
    commands to execute on remote host go here...
    exit
    EOF
    sleep 10
    done

    In fact, I just tested it locally on my system and it worked.
    Hi Ped - Ahh yes, your right, that will work. I had not thought of of that method. To do a simple ssh to any number of host this is a cleaver way - good thinking Nick

  7. #17
    ped
    ped is offline
    Just Joined!
    Join Date
    Jun 2005
    Posts
    4
    Thanks, Nick...

  8. #18
    Just Joined!
    Join Date
    Mar 2008
    Posts
    2

    remoteex.sh

    #/bin/sh

    declare the variables for your task
    like:

    HOST_FILE=<path to the host file>

    for H in $(cat $HOST_FILE)
    do
    ping -c1 -t1 $H 2>&!
    TEST=$?

    if [ $TEST = 0 ]; then
    ssh $H "execute teh command to perform your task"
    fi
    done

Page 2 of 2 FirstFirst 1 2

Posting Permissions

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