Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I am new to shell scripting .I want to take help from all the experts here .
I want to write a shell script (to be run on linux machine) to invoke 'n' numbers of ssh window and execute commands on these ssh windows at once .Please provide your expert help
If I understand you right, all you need to do is put lines in a bash-file like this:
#!/bin/bash
ssh user@server1 <command> &
ssh user@server2 <command> &
The commands will simply be executed, but you won't get new ssh windows. Do you really need that?
Then of course, if you don't want to type in password you need to configure ssh to login with certificate (aka "key").
You have to setup password less ssh setup for each machine.
If you are using OpenSSH, then it may not possible to run the commands at the same time on 'n' number of ssh window, as you have to relogin again and again in a loop to execute commands on each.
Instead you can use pssh(parallel ssh) to run your command parallelly on each machine.
e.g.
Quote:
pssh -h <host-file> date
Here you can run date command parallely on each hosts present in the file <host-file>
see the manual for different options.
Last edited by divyashree; 07-21-2012 at 12:19 PM.
It is required for me to open new windows and the commands gets executed on these windows as i have to watch and go through the logs on each
ssh windows .
@Divyashree : I don't have pssh installed on my client machine.I first want to know if we can automate my requirement using shell/perl script
To make things clear here is what i want to do
Run a script which opens up 'n' number of ssh windows and then on each the required command gets executed on parallel . Is this possible?
It is required for me to open new windows and the commands gets executed on these windows as i have to watch and go through the logs on each
ssh windows .
@Divyashree : I don't have pssh installed on my client machine.I first want to know if we can automate my requirement using shell/perl script
To make things clear here is what i want to do
Run a script which opens up 'n' number of ssh windows and then on each the required command gets executed on parallel . Is this possible?
Dear iwlu212 without using pssh/cssh , the commands cant be executed at once/parallel, but one after another.
What you need can be changed as : open 'n' numbers of windows/terminals and then run ssh in each to do something.
You can use like this in your script to open a new terminal and run some command in them:
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.