1

I have the need to run some simple commands on multiple remote hosts, then view the output side by side. For example I might want to run:

cd /var/log/server
grep 'UUID: 12345-12345-12345' *.log

Then check that there are 15 lines returned and they all look the same, across a dozen remote hosts.

What tools are available to help me do this without having to switch between multiple tabs and type or copy/paste a bunch of commands?

4
  • Can we assume all of the remote hosts are running macOS? Do you have direct network access to all of them?
    – bmike
    May 5 at 0:21
  • What do you mean with "side by side", where do you want to see the output?
    – nohillside
    May 5 at 6:08
  • I know that you can do things like that with MobaXTzrm on windows but I have not yet found equivalent on MacOS.
    – Ptit Xav
    May 6 at 9:31
  • in some cases the remote hosts are Linux, in others they're various routers. "side by side" as in the terminal windows on my Mac are sitting next to each other. For example I might be looking for the actions of a specific client across multiple log files. One option I am exploring is Ansible ad-hoc commands, where the results will appear "side by side" by actually being on top of each other in the one terminal window. I'm also trying to find AppleScript that will let me broadcast commands to a selection of terminal windows/tabs. Not holding my breath on that.
    – ManicDee
    May 8 at 23:42

2 Answers 2

0

Using Alfred Clipboard History

This is a slight enhancement of the copy-paste option that relies on the Alfred app — Alfred is a launcher, providing a faster way to launch applications or perform certain tasks by typing instead of navigating the GUI. In this case we're using one feature of Alfred which is Clipboard History. Alfred will remember the last day's worth of Clipboard activity.

  1. Create a text file containing the commands you want to use

  2. Select each command and copy it to the clipboard (Command+C)

  3. For each terminal window or tab:

    1. Open Alfred Clipboard History (default is Command+Option+C)
    2. Select the command to paste
    3. (repeat those two steps for each command)

For me, writing the commands down ahead of time is part of planning what I'm going to do, and also documenting what I've done so my colleagues can pick up any routine task and hit the ground running.

How does this help?

Using Alfred Clipboard History in this way saves the back-and-forth between the text file and the terminals, reducing the risk of accidentally selecting a sequence of characters instead of the whole command, or accidentally deleting commands with Command-X instead of copying with Command-C, or moving blocks of text around as editors such as BBEdit allow you to do by simply dragging a selected block of text.

This option doesn't require advanced knowledge of tools like Ansible.

Problems with this option

This option can lead to confusion because Alfred's Clipboard History simply lists the clipboard history and you need to remember the order to invoke the commands in. For one or two commands, it's pretty safe. Once you have five commands you might end up invoking them out of order. In some cases you can copy blocks of commands or use ';' to separate commands on one line.

0

If you have ssh access to all remote systems, you can run

for h in user@server1 user@server2 user@server3; do
    echo "===== $h ====="
    ssh "$h" sh -c 'cd /var/log/server; grep "UUID: 12345-12345-12345" *.log'
done

to display the data in Terminal.

To automatically do the checking, you can redirect the output from each server to its own file and then use diff to check whether they are equal.

1
  • Similarly I could use Ansible ad-hoc commands, which return the results in a JSON reply. I'll write that up once I am comfortable with Ansible. Thanks for this shell example!
    – ManicDee
    May 8 at 23:44

You must log in to answer this question.

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