LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-26-2008, 11:53 PM   #1
kushkothari
Member
 
Registered: Oct 2008
Posts: 31

Rep: Reputation: 15
Question help for high level shell script


I want to ssh to a server from that server I have to ssh to 5 different nodes and then run 5 different program one on each

my approach:

Code:
xterm  -e "ssh -t  user@server ssh node0  ./x1.sh node0 1" &
xterm  -e "ssh -t  user@server ssh node1  ./x1.sh node1 1" &
xterm  -e "ssh -t  user@server ssh node2  ./x1.sh node2 1" &
xterm  -e "ssh -t  user@server ssh node3  ./x1.sh node3 1" &
xterm  -e "ssh -t  user@server ssh node4  ./x1.sh node4 1"
*x1.sh runs a server or client according to the parameter passed to it.


problem with this code

it opens a window do something and just close it

requirement
i should see first 4 windows and should be able to type on 5 window
with xterm i am not able to get it.

can anyone help me?
 
Old 10-27-2008, 12:39 AM   #2
abolishtheun
Member
 
Registered: Mar 2008
Posts: 183

Rep: Reputation: 31
maybe put the "./x1.sh node0 1" in .profile on the remote hosts?
 
Old 10-27-2008, 01:10 AM   #3
kushkothari
Member
 
Registered: Oct 2008
Posts: 31

Original Poster
Rep: Reputation: 15
no it won't work as I have same memory space for all the node and the server
and even if i have diff. space i have to keep on changing the parameter like node0 node1 node2
 
Old 10-27-2008, 01:25 AM   #4
abolishtheun
Member
 
Registered: Mar 2008
Posts: 183

Rep: Reputation: 31
then maybe:

Code:
 xterm -e 'ssh -t node0 "./x1.sh node0 1  && bash -i"'
?

Last edited by abolishtheun; 10-27-2008 at 01:29 AM. Reason: forgot you wanted it to be in an xterm
 
Old 10-27-2008, 02:30 AM   #5
kushkothari
Member
 
Registered: Oct 2008
Posts: 31

Original Poster
Rep: Reputation: 15
thanks for the reply
but still the same problem window is getting closed after few microseconds.
 
Old 10-27-2008, 02:48 AM   #6
burschik
Member
 
Registered: Jul 2008
Posts: 159

Rep: Reputation: 31
As far as I understand it, xterm will close the window as soon as the script you are running on the remote machine has terminated. If you don't want the window to close, you will have to stop that script from terminating.
 
Old 10-27-2008, 02:56 AM   #7
kushkothari
Member
 
Registered: Oct 2008
Posts: 31

Original Poster
Rep: Reputation: 15
ya what u suggested is right I open 5 terminal on my PC and tried these command without xterm and it's working fine

but I have to run these command in new terminal automatically

and I don't know how the window is getting closed because 4 out 5 machine are server and they keep on listening for the client then how it's getting terminate

Could you tell me how to do this might be using something else like konsole (i tried this one but seems doesn't work)
 
Old 10-27-2008, 02:58 AM   #8
kushkothari
Member
 
Registered: Oct 2008
Posts: 31

Original Poster
Rep: Reputation: 15
i tried this code


ssh -t user@server ssh node "./x1.sh node1 1 && bash -i"

it's working fine but I have to do this in new terminal?
 
Old 10-27-2008, 04:40 AM   #9
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,928

Rep: Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612
A couple of ideas:
xterm -e "/bin/bash -c 'ssh -t user@server ssh node0 ./x1.sh node0 1 &'"

xterm -hold -e "ssh -t user@server ssh node0 ./x1.sh node0 1" &
 
Old 10-29-2008, 05:52 PM   #10
kushkothari
Member
 
Registered: Oct 2008
Posts: 31

Original Poster
Rep: Reputation: 15
Thanks a lot
I tried the second one it's working

I am running server client by using this command on 5 different pcs
when I do it manually like open 5 terminal ssh to server then node then running program on those nodes it's working fine

but when I try to do the same using above command processing speed is very very slow and sometime it do nothing.

another problem is in releasing the port number (as it doesn't happen during the normal run). I think there is some problem when my program is ending. it's not getting closed properly. how can I fix it?
 
Old 10-29-2008, 08:24 PM   #11
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
why is there a need to use xterm? am i missing something, because you can just put all your ssh commands in the script.
 
Old 10-29-2008, 09:25 PM   #12
kushkothari
Member
 
Registered: Oct 2008
Posts: 31

Original Poster
Rep: Reputation: 15
I have to ssh to one server then from there i have to ssh to few nodes say 5.
now I have to run 5 different program for each node (server-client program) so all program are connected.
In one of the five window I have to give the input. but before giving input I have to see one value on all the other nodes if it's ok then only I will give the input otherwise I have to restart from initial.

I am using xterm because people in this forum told me to do so I don't know if there is any other way to do so (I am new to linux).

If you have a another way to do so then please help me, Thanks
 
Old 10-29-2008, 10:41 PM   #13
abolishtheun
Member
 
Registered: Mar 2008
Posts: 183

Rep: Reputation: 31
Quote:
Originally Posted by kushkothari View Post
but before giving input I have to see one value on all the other nodes if it's ok then only I will give the input otherwise I have to restart from initial.
Ever thought about automating this step? I mean, how do you know it's "OK" to proceed? If it's by looking at output given by the x1.sh program (does it print "ok to proceed" or something obvious?) then you can just parse the output and automate it.
 
Old 10-29-2008, 11:16 PM   #14
kushkothari
Member
 
Registered: Oct 2008
Posts: 31

Original Poster
Rep: Reputation: 15
following are more details:

Server(node0)-agent3(node1)-agent2(node2)-agent1(node3)-client(node4) that's how I have 5 nodes.

now when I will run my program I have to look for one variable (it will be printed on agent1 itself) at node3 i.e. agent1 if it's 0 it's working fine if not then restart from beginning. I have to run one set for 5 times and there are 18 different sets. that means I have to start and all five program 90 times.

now the problem is when I try to do this using xterm and give ctrl+c instead of only closing the server or client (where ever i am giving ctrl+c) it's directly closing the connection with the server and that's the problem. because my server/client is not properly exited. when I try to run it for another iteration it's facing a problem with port binding. (address is already in use.)

Last edited by kushkothari; 10-29-2008 at 11:17 PM.
 
  


Reply

Tags
commands, multiple, solution, ssh


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
Shell script to store high water mark for uptime. McSlack Programming 5 10-18-2008 02:13 PM
LXer: MochiKit feels like Python but delivers high-level JavaScript LXer Syndicated Linux News 0 11-29-2006 08:21 AM
High-level question about printing via a router? gtjmn308 Linux - Networking 2 09-23-2006 09:21 AM
shell script problem, want to use shell script auto update IP~! singying304 Programming 4 11-29-2005 05:32 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:58 PM.

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
Open Source Consulting | Domain Registration