LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-16-2011, 02:06 AM   #1
ytyyutianyun
Member
 
Registered: Nov 2011
Posts: 63

Rep: Reputation: Disabled
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 &
 
Old 11-16-2011, 03:07 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
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.
 
1 members found this post helpful.
Old 11-16-2011, 10:42 PM   #3
ytyyutianyun
Member
 
Registered: Nov 2011
Posts: 63

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by colucix View Post
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

Last edited by ytyyutianyun; 11-16-2011 at 10:43 PM.
 
Old 11-17-2011, 01:00 AM   #4
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,331
Blog Entries: 55

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


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
ssh with in the node is not working sunilkokirala Linux - Software 1 02-03-2011 10:26 AM
Replace node(s) from xml file in shell BassKozz Linux - Newbie 4 06-03-2009 09:59 PM
SSH from master node to compute nodes w/out passwd haiders Linux - Networking 2 09-20-2006 12:50 PM
Need to SSH into cluster node by machine name !? nuro305 Linux - Networking 3 06-23-2006 11:41 PM
how do I SSH into a cluster node? dogma Linux - Newbie 4 05-15-2003 05:31 PM


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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration