LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Help!A ssh node problem in the shell (https://www.linuxquestions.org/questions/linux-newbie-8/help-a-ssh-node-problem-in-the-shell-913775/)

ytyyutianyun 11-16-2011 01:06 AM

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 &

colucix 11-16-2011 02:07 AM

That's correct. The first ssh statement does only a login to node1 and then sticks waiting for user input at the prompt of node1 itself. Instead if you want to pass some command to be executed on node1 you need to specify them as standard input and don't forget the exit command to terminate the ssh session. For multiple commands you can try a here document:
Code:

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

Hope this helps.

ytyyutianyun 11-16-2011 09:42 PM

Quote:

Originally Posted by colucix (Post 4525275)
That's correct. The first ssh statement does only a login to node1 and then sticks waiting for user input at the prompt of node1 itself. Instead if you want to pass some command to be executed on node1 you need to specify them as standard input and don't forget the exit command to terminate the ssh session. For multiple commands you can try a here document:
Code:

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

Hope this helps.


Thanks! You are great.it's helpful.
When I posted this, I continued searching some solutions and find "rsh" can do my thing. But I only can execute only one command and maybe I will learn it. Last of all, thanks

unSpawn 11-17-2011 12:00 AM

There's another way if the 'at' service is running: save the script on the node then 'at -f /path/to/script'.


All times are GMT -5. The time now is 08:19 AM.