Welcome to Linux Forums!

With a comprehensive Linux Forum, information on various types of Linux software and many Linux Reviews articles, we have all the knowledge you need a click away, or accessible via our knowledgeable members.

Linux Forum ArticlesLinux ForumsLinux Forum DownloadsLinux HostsFree MagazinesJobs
Home|Register|FAQ|Member List|Calendar|Unanswered Posts|Forum Rules|Today's Posts|Advanced Search|
SEARCH FOR IN
Go Back   Linux Forums > GNU Linux Zone > Linux Programming & Scripting
Reload this Page Running Multiple Commands Using SSH
Linux Forums
Linux Forums
Welcome To The Linux Forums!
Welcome to Linux Forums. We pride ourselves in being one of the largest Linux communities on the web, we encourage you to REGISTER on our forums and participate in the community. There are over 150,000 members ready to answer your questions. JOINING US today will allow you to make new posts, get support, send messages to other members and submit downloads to our downloads directory and many other great features!

Linux Programming & Scripting C, Perl, PHP, Bash Scripts, anything programming or script related post in here!

Reply
 
Thread Tools Display Modes
Old 12-27-2007   #1 (permalink)
Just Joined!
 
Join Date: Dec 2007
Posts: 5
Arrow 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:

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
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.

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
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, namely

Code:
ssh -X $i     # after this command, inside workstation B
DISPLAY=10.0.0.96:0.0
export DISPLAY                    
/usr/local/abc/myscript.sh
then I have no problems.

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!
cyap6176 is offline   Reply With Quote
Old 12-28-2007   #2 (permalink)
Linux Newbie
 
Join Date: Jun 2007
Posts: 224
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' & 
vsemaska is offline   Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off
 

Similar Threads
Thread Thread Starter Forum Replies Last Post
commands not running "(slackware)" bunty82 Linux Newbie 7 10-12-2007 04:12 PM
Bash script commands during commands ihth Linux Programming & Scripting 4 07-09-2007 10:32 PM
Trouble executing multiple commands simultaniously Mercury Sentinel Linux Programming & Scripting 2 08-04-2005 01:33 PM
multiple users running VNC slacker Linux Applications 10 03-17-2003 10:31 PM

Free Magazines
Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe
Systems Management News, the newspaper for IT systems administration and data center managers!
Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe
The Enterprise Newsweekly
eWeek is the essential technology information source for builders of e-business.
subscribe
Oracle Magazine
Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe
Total Telecom
Total Telecom is "The Economist of the communications industry".
subscribe
More free magazines »



All times are GMT. The time now is 08:20 PM.




© 2000 - 2008 - All Rights Reserved - Property of  MAS Media

Content Relevant URLs by vBSEO 3.2.0