-1

I use a script which after execution opens different tabs and connects to different servers(using ssh). Now along with that,I want to run another command (say 'pwd').So how to do that?

gnome-terminal --tab -e 'ssh user@ip1' --tab -e 'ssh user@ip2'

This opens 2 tabs and connects to corresponding ip.After ssh in every tab I want to run another command, so that there will be two tabs,and after connecting to ip it will run specified command

Mustafa DOGRU
  • 3,994
  • 1
  • 16
  • 24
rohit264
  • 13
  • 3
  • Have you tried chaining commands like this `ssh user@ip2 && cmd && cmd`? –  Oct 21 '16 at 08:43

2 Answers2

0

Use ansible, fabric or any automation tool like any of these to do that you want. this tools allow execute a same command via ssh in multiple machines at same time in simple way.

using ansible you only need to do somthing like this

    ansible <your-list-of machine> -m shell -a "your command"

example

    ansible ip1 -m shell -a "echo $TERM"
johnnymnmonic
  • 774
  • 8
  • 11
0

You need to use SSH ability to execute remote command, like this:

gnome-terminal --tab -e "ssh -A -t user@ipbridge \"ssh -t user@ip1 'pwd; /bin/bash -i'\"" 

Note the /bin/bash -i after the command. It is needed, because otherwise ssh will exit after the command.

Hardy Rust
  • 1,600
  • 1
  • 10
  • 12