3

Is there any app or "trick" to use Terminal to mirror commands to different ssh hosts (clusters, usually)?

I do not want to use another terminal application.

EDIT: sorry but the revision from timothymh actually made the meaning of my question to be different. What I would like is an application where I can manually issue mirrored commands to different servers while I am working on them, not a script or a system (like Puppet) to just issue known commands. That's why I mentioned that I hate those I tried (iTerm2 and so on) because of the look and feel.

I like the way the standard terminal app behaves and looks in term of fonts, keyboard mapping, way of scrolling up and down and so on.

  • I don't understand your question – CousinCocaine Oct 28 '15 at 18:08
  • @CousinCocaine because the edit took away the original question...if you use iTerm2 you know that you can ssh to multiple hosts (between other things) and issue on them the same command. Now, if you also use the Apple terminal.app you notice how the look and feel is different, the keyboard is mapped differently, the scroll wheel acts different. I don't like iTerm2, I would like terminal.app to control several hosts. Or what alternatives are out there, excluding terminator and csshx? – maraboshi Oct 28 '15 at 22:31
  • What is meant by "mirror commands"? What is a "mirrored command"? – l --marc l Jan 4 '16 at 21:22
  • It means while you type, the input goes to multiple terminals (so all servers) and you don't have to type it separately onto each. – maraboshi Jan 6 '16 at 10:30
5

You can write a shell script and put it in ~/.bashrc like this:

function do_some_thing() {
  command="fab -R localhost deploy --set sha=master"
  ssh -t ubuntu@1.2.3.4 -C "$command"
  ssh -t ubuntu@1.2.3.5 -C "$command"
  ssh -t ubuntu@1.2.3.6 -C "$command"
  ssh -t ubuntu@1.2.3.7 -C "$command"
}

However there are various tools you can use for this type of activity, like Chef or Capistrano or various others.

  • 1
    This is an obvious, but very cool trick. You could also create a shell script that does something similar and takes the command as an input ($1). – CousinCocaine Oct 27 '15 at 19:16
  • 1
    I would add Ansible to the list of recommended tools (has its own advantages such as being agent-less and slightly less intimidating to learn). – willWorkForCookies Oct 27 '15 at 21:20
  • Thanks guys, but that's not what I need, please see the edit (of the edit :-) ) – maraboshi Oct 28 '15 at 16:21
  • I strongly recommend something like the mentioned tools -- ansible, chef, puppet, capistrano, or docker, to do your sysadmin work. Manually typing commands on multiple hosts is not the efficient, modern or professional way to do sysadmin. Maybe you have your reasons :) also, in case you missed it, the 'command' above can just be $1, so you'd do $ do_some_thing rm /var/log/system.log to remove system.log on all the hosts. – court3nay Oct 28 '15 at 20:32
  • @court3nay I already use Puppet to manage things, but there are many reasons to ssh and do manual stuff :-) – maraboshi Oct 28 '15 at 22:27
1

you can use pdsh, even if you have Chef its going to be faster. with Chef, knife-search (inherent in knife-ssh) is an expensive operations, but you can dump the results of the search knife search node role:base -i > base.nodes and then use pdsh (written in C) to operate on the set (obviously you can do this part without Chef). pdsh -w^base.nodes "sudo whoami" or whatever. pdsh comes with a companion tool dshbak which can summarize the output of the hosts into a convenient report for you, too.

just make sure that you arent doing one-off management at a massive scale using tools like this. its great for auditing and kicking off jobs, but it is not a replacement for config management.

  • Thanks Jake, but I need to SSH into the hosts, not to simply run commands on the fly. I need the shell. – maraboshi Jul 31 '17 at 11:14
  • 1
    then theres cluster-ssh brew install csshx for Terminal.app or gem install i2cssh for iterm2 – Jake Plimack Aug 1 '17 at 15:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .