rohit264 rohit264 - 1 month ago 19
Bash Question

execute one command in all open tabs in a terminal

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

Answer

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"