Results 1 to 2 of 2
I am fairly new to (bash) shell scripting and am in need of assistance.
Consider workstations A and B. I want to be able to log into workstation A and ...
- 12-27-2007 #1Just Joined!
- Join Date
- Dec 2007
- Posts
- 5
Running Multiple Commands Using SSH
I am fairly new to (bash) shell scripting and am in need of assistance.
Consider workstations A and B. I want to be able to log into workstation A and then from there log into workstation B. Once inside workstation B, I want to set the DISPLAY environment variable, run a script, then exit out and return to workstation A again to repeat this process for whatever number of workstations.
Below is my code:
The obvious problem with this code (I know) is the ssh -X line. In particular, the script will stop running at this point which I do not want.Code:# # Workstation IP addresses # workstation[0]=10.0.0.1 workstation[1]=10.0.0.2 workstation[3]=10.0.0.3 # # function : startClient() # description: start clients at workstations # function startClients() { # # Start all clients # for i in ${workstation[@]} do echo "Starting Client at $i..." ssh -X $i # script stops here once I am ssh'd DISPLAY=10.0.0.96:0.0 # into the remote workstation export DISPLAY /usr/local/abc/myscript.sh echo "Exiting from $i..." done } startClients
I've already tried these variations (a command delimited by semicolons and a command enclosed in quotes delimited by semicolons) with no luck:
Code:ssh -X $i DISPLAY=10.0.0.96:0.0; export DISPLAY; /usr/local/abc/myscript.sh
If I were to do this process from my workstation (A) manually, namelyCode:ssh -X $i 'DISPLAY=10.0.0.96:0.0; export DISPLAY; /usr/local/abc/myscript.sh'
then I have no problems.Code:ssh -X $i # after this command, inside workstation B DISPLAY=10.0.0.96:0.0 export DISPLAY /usr/local/abc/myscript.sh
Can someone please point me in the right direction? I need to be able to execute all these commands once logged into workstation B.
Thanks for your help!
- 12-28-2007 #2Linux User
- Join Date
- Jun 2007
- Posts
- 318
The reason the script stops running at the 'ssh -X' line is because the script is waiting for the 'ssh' command to finish.
To get what you want to do is to run each 'ssh' command as a background process. This is done by putting a '&' at the end of the 'ssh' command:
Code:ssh -X $i 'DISPLAY=10.0.0.96:0.0; export DISPLAY; /usr/local/abc/myscript.sh' &


Reply With Quote