Find the answer to your Linux question:
Results 1 to 5 of 5
I want to enter the command step by step automatically with a shell when I run the shell,the program only jump to ssh node1,and do nothing else. Help and thanks. ...
  1. #1
    Just Joined!
    Join Date
    Nov 2011
    Posts
    3

    Help!A ssh node problem in the shell

    I want to enter the command step by step automatically with a shell

    when I run the shell,the program only jump to ssh node1,and do nothing else.
    Help and thanks.
    Here is the program:

    #!/bin/bash
    ssh node1
    cd /us1
    nohup matlab < pi11081.m >& name.out &
    cd /us2
    nohup matlab < pichuli2.m >& name.out &
    ssh node2
    cd /us1
    nohup matlab < pichuli3.m >& name.out &
    cd /us2
    nohup matlab < pichuli4.m >& name.out &
    ssh node3
    cd /us1
    nohup matlab < pichuli5.m >& name.out &
    cd /us2
    nohup matlab < pichuli6.m >& name.out &

  2. #2
    Just Joined!
    Join Date
    Oct 2011
    Posts
    15
    I am sure it is not possible directly putting those commands in the script.
    You need to use a loop and a conditional like

    for host in node1 node2
    do

    and a conditional inside the loop.

    if [ "$host" == "node1" ]; then
    command for node1
    fi

    or use switch case.

    experts will give you better advices, but by the time you can work on this.

  3. #3
    Linux Enthusiast scathefire's Avatar
    Join Date
    Jan 2010
    Location
    Western Kentucky
    Posts
    616
    Is it executing all the commands for node1? Or is it hanging at the login? You may want to put the commands inside of ssh, otherwise your script will not execute them remotely.

    e.g. for node1

    Code:
    ssh node1 cd /us1;nohup matlab < pi11081.m >& name.out &;cd /us2;nohup matlab < pichuli2.m >& name.out &
    linux user # 503963

  4. #4
    Just Joined!
    Join Date
    Nov 2011
    Posts
    3
    Quote Originally Posted by scathefire View Post
    Is it executing all the commands for node1? Or is it hanging at the login? You may want to put the commands inside of ssh, otherwise your script will not execute them remotely.

    e.g. for node1

    Code:
    ssh node1 cd /us1;nohup matlab < pi11081.m >& name.out &;cd /us2;nohup matlab < pichuli2.m >& name.out &
    Thanks. I ask others,then he pu this for me

    ssh -n -f node1 "sh -c \"cd /us1; nohup matlab <pi11081.m >& name.out &\""

    then why ? Thanks

  5. #5
    Linux Enthusiast scathefire's Avatar
    Join Date
    Jan 2010
    Location
    Western Kentucky
    Posts
    616
    The quotes are to escape any special characters, and therefore keeping your script from breaking.
    linux user # 503963

Posting Permissions

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