[切换到中文]
This article is machine translated
OnTheSSH supports sending the same command to multiple remote hosts simultaneously for execution. Let’s take a look at an example first:

The above figure shows the situation where the command ‘STR=”hello”;echo $STR;’ is sent simultaneously to four remote hosts for execution. Two hosts print out the content of the variable STR (green), while the other two hosts fail to connect and display error messages (red).
When executing commands on multiple hosts, the exec protocol in SSH is used. Note that there are two differences from the shell terminal we usually use:
- The shell has an interactive environment. A previous command may affect the execution result of the next command. For instance, in the shell terminal, it is perfectly fine to first execute the command STR=”hello” and then the command echo $STR, as these two commands are in the same session. Each command execution in the exec protocol starts with the creation of an SSH connection and automatically closes the SSH connection at the end of the execution. If the STR=”hello” command is sent first for execution and then the echo $STR command is sent, the variable content cannot be printed out because the two exec executions are not in the same session. Therefore, if you need to execute multiple commands, you can use semicolons to concatenate these commands together, as shown in the example above.
- After the shell terminal is created, it will automatically save some environment variables, such as the width and height of the terminal window, so that programs like top or vim can be displayed in full screen. The exec protocol does not have these environment variables, so top or vim cannot be run.
On the right side of the title bar in the input area, there are some built-in shortcut commands. These commands are suitable for execution on multiple hosts. You can obtain and execute them from the drop-down list, add or modify them, or refer to them to write your own commands.