Shell Script for Invoking SSH
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:
see the manual for different options. |
You can also use cssh(clusterssh).
|
Hi Divyashree and Pingu thanks for your reply !!
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? |
Quote:
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: Code:
gnome-terminal -e <your-ssh-to-othermachine-to-run-some-command> Quote:
|
Divya thanks again for your reply .I tried the command but got an error can you please correct it .
gnome-terminal -e ssh root@x.x.x.x Invalid argument: "root@x.x.x.x" |
Quote:
e.g. Code:
gnome-terminal -e "ssh root@localhost sleep 1 && ls -lrth && sleep 1" |
Hi Divya !! yes the below option works but after the command execution the ssh terminal gets killed , i want it to remain open and not get killed
I am using it gnome-terminal -e "ssh user$hostname command" What modification is required for the command to get excuted and window not getting closed Thnx Again |
Quote:
Code:
gnome-terminal -e "ssh localhost command; read line" |
Thnx Divya !! yes now it is not getting closed but i am stuck in another problem .. i am using it as mentioned below
gnome-terminal -e "ssh host_name@host for i in `seq 1 2` ; do echo hello_$i;done;read line" but the output i am getting is hello_ hello_ and i want it to be hello_1 hello_2 the value of variable i is not getting interpreted . how can we make this work Thanks Again |
All times are GMT -5. The time now is 11:05 PM. |