Configure a cluster of ssh hosts and run terminal commands simultaneously on each node. This can be useful when dealing in a distributed environment and you need to manage multiple remote compute nodes. There are predefined commands available but you can also run completely custom commands. You can easily customize the extension to add a custom command prefix/suffix to each command execution on cluster and host level.
This extension requires OpenSSH to be installed on your machine. Most Unix based systems (Linux and Mac Os X) provide it by default. On Windows you can install ssh via Cygwin.
You can check if ssh is installed on your machine by typing ssh
in your favourite system terminal.
If it shows the usage information, you are ready to go.
- Configure a cluster of ssh hosts to run commands simultaneous on each node
- Open a ssh terminal for each host in the configured cluster
- Run custom terminal commands on each ssh host of the configured cluster
- Run selected text as a terminal command on each ssh host of the configured cluster
- Run one of the following predefined terminal commands on each ssh host of the configured cluster
- initiate shutdown
- initiate restart
- show system info
- show hardware info
- show a list of running processes
- show the free memory
- show the current date
- show the open ports
- show the current working directory
- list files in current directory
- show the hostname
- show the network configuration
- Configure a command prefix/postfix on cluster and ssh host level
- Supports commands for bash, cmd and powershell
- Configure a cluster of ssh hosts. See Hosts Configuration
- Press
F1
and search for Cluster Ctrl to run any available command.
- Alternatively, you can select some text, perform a right click and select the menu item Cluster Ctrl: Run Selection as Command.
The status bar item indicates the status of the cluster and can be used to open up the output console. Any output of the hosts of the cluster will be redirected to this view. Additionally, you can define a command prefix and postfix which for example can be used to customize the command output.
This section describes in detail how to configure a cluster of multiple ssh hosts for the extension and the additional configuration parameters that you can set.
Configure multiple ssh host by adding a Host Definition for each host to the ctrl.cluster.hosts
list property in the settings (has to be edited in the settings file). A simple ssh host entry can look like this:
"ctrl.cluster.hosts": [
{
"host": "192.168.178.20"
},
]
This requires that you have already configured your username and key file to be used for this ssh host in your ssh configuration file ~/.ssh/config
. Otherwise, you must add the user
and identityFile
properties. The detailed list of all supported properties of a ssh host entry can be seen in the following section.
A host is defined by:
key | type | required | description |
---|---|---|---|
host |
string |
yes | host address or hostname to be used for the ssh connection (ideally the same host is configured in ~/.ssh/config ) |
user |
string |
no | username to be used for the ssh connection (overrides the User specified in ~/.ssh/config if set) |
identityFile |
string |
no | identity file to be used for the ssh connection (overrides the IdentityFile specified in ~/.ssh/config if set) |
prefix |
string |
no | set a prefix that will be prepended to every command of this particular host. |
suffix |
string |
no | set a suffix that will be appended to every command of this particular host. |
This extension contributes the following settings:
setting id | default | type | description |
---|---|---|---|
ctrl.cluster.name |
"My Cluster" |
string |
set cluster name to personalise your cluster. |
ctrl.cluster.timeout |
5 |
number |
set the timeout for the ssh command. |
ctrl.cluster.flavor |
"bash" |
[bash, cmd, pwsh] |
set the flavor of the remote hosts shell. Select bash for Mac Os X or Linux, and select either cmd (Command Prompt) or pwsh (PowerShell) for Windows. |
ctrl.cluster.prefix |
"" |
string |
set a prefix that will be prepended to the command string on every command execution on every host. |
ctrl.cluster.suffix |
"" |
string |
set a suffix that will be appended to the command string on every command execution on every host. |
ctrl.cluster.hosts |
[] |
array |
the ssh hosts that make up your cluster. A list of Host Definitions. |
ctrl.cluster.commands.shutdown |
{ |
object |
Set the initiate shutdown command for each platform |
ctrl.cluster.commands.restart |
{ |
object |
Set the initiate restart command for each platform |
ctrl.cluster.commands.systemInfo |
{ |
object |
Set the show systemInfo command for each platform |
ctrl.cluster.commands.hardwareInfo |
{ |
object |
Set the show computer info command for each platform |
ctrl.cluster.commands.processList |
{ |
object |
Set the show process list command for each platform |
ctrl.cluster.commands.memory |
{ |
object |
Set the show memory command for each platform |
ctrl.cluster.commands.date |
{ |
object |
Set the date command for each platform |
ctrl.cluster.commands.ports |
{ |
object |
Set the show open ports command for each platform |
ctrl.cluster.commands.workingDirectory |
{ |
object |
Set the show current directory command for each platform |
ctrl.cluster.commands.listFiles |
{ |
object |
Set the list files command for each platform |
ctrl.cluster.commands.hostname |
{ |
object |
Set the show hostname command for each platform |
ctrl.cluster.commands.networkConfiguration |
{ |
object |
Set the show network configuration command for each platform |
This sections provides some sample configuration snippets that can be included in the settings.json
file.
-
Prefix the command output of every node with their hostname:
"ctrl.cluster.prefix": "echo -n \"[$(hostname)]\";"
-
Execute every command of a particular node in a specific directory:
"ctrl.cluster.prefix": "echo -n \"[$(date +%D%T)] \";", "ctrl.cluster.hosts": [ { "host": "192.168.178.20", }, { "host": "192.168.178.30", "prefix": "cd ~/tmp && " }, ]
-
Use
ifconfig
for the show network configuration command on Unix hosts:"ctrl.cluster.commands.networkConfiguration": { "bash": "ifconfig", "cmd": "ipconfig /all", "pwsh": "Get-NetIPConfiguration" }
-
Configure the cluster to use the powershell commands. Use this option if you have a cluster of Windows hosts that use powershell as default terminal:
"ctrl.cluster.flavor": "pwsh"
-
Suppress any program errors of the ssh hosts when running a command on your cluster:
"ctrl.cluster.suffix": " 2> /dev/null"
The Change Log can be found here.
Fork the repo, create a branch and submit pull requests.