Configuration structure

In the subfolder ./config/ are all configuration files

├── config
│   ├── commands.txt
│   ├── default
│   │   ├── commands.txt
│   │   └── serverlist.json
│   └── userconfig.sh

User configuration

The file ./config/userconfig.sh will be created on the first run and updated during usage when setting a command, tag or profile.

The file is plain bash shell script and will be sourced by multi_ssh.

Do not add other variables here - it will be overwritten on next save process.

#!/bin/bash
# CONFIG for multi_ssh.sh - saved Wed May 15 15:50:16 CEST 2024

# profile
export MRE_PROFILE=default

# admin user to connecto to other hosts
export MRE_SSHUSER=sshuser

# terminal program to open per connection
export MRE_TERMINAL=gnome-terminal

# filter hosts, set command
export MRE_TAGS=""

# command to execute on target host(s)
export MRE_COMMAND="hostname -f"

# colors
export COLOR_PRESET_cmd=( blue )
export COLOR_PRESET_bastion=( purple )
export COLOR_PRESET_lastexec=( green )
export COLOR_PRESET_terminal=( brown )
export COLOR_PRESET_prompt=( green )
export COLOR_PRESET_output=( darkgray )
export COLOR_PRESET_ok=( green )
export COLOR_PRESET_error=( red )

Variables:

  • COLOR_PRESET_(…): {array} foreground and background color for a few presets.
  • remotecommand: {string} saved remote command
  • sshuser: {string} a user to be used for ssh connection. If a connection is via bastion host this user is used for bastion and for target.
  • taglist: {string} savd list of tags seperated by space. The active servers are these that match all given tags (AND condition).
  • terminal: {string} command to start a terminal. In it the ssh command will be executed. If a command will be executed you get a single terminal per target. The terminal must know the param “-e” to execute a command. Known as compatible: gnome-terminal (default), konsole (KDE), xterm

Commands

The file ./config/commands.txt is a textfile with pre defined commands you want to use more often on all systems. The file is just plain text. Structure its content like you want.

Example:

# --- simple things / testing
hostname -f
sleep 20

# --- reboot a system
sudo reboot

Remark:

You can add an additional commands.txt in a profile directory. See profiles below.

Profiles

Below the config directory you can create subdirectories to create custom profiles.

A subfolder “default” is delivered with *.dist files.

Each new profile can contain these files

  • commands.txt
  • serverlist.json

File commands.txt

A ./config/<profile>/commands.txt in a profile directory is optional. It will be shown when setting a command. Its content will be displayed below the content of ./config/commands.txt.

File serverlist.json

A file ./config/<profile>/serverlist.json is required. It contains all servers you want to handle with that profile.

This is the example configuration in the dist file:

{
    # ------------------------------------------------------------------
    # maintenance windows
    # ------------------------------------------------------------------
    "maintenance":[
        {"label":"mon",      "description":"Monthly maintenance window on Monday"},
        {"label":"tue",      "description":"Monthly maintenance window on Tuesday"}
    ],

    # ------------------------------------------------------------------
    # S E R V E R   C O N F I G
    # ------------------------------------------------------------------
    "servers":[
        {"host":"server-01.example.com",                   "tags":["live","mon","apt"]},
        {"host":"server-02.example.com",                   "tags":["live","mon","apt"]},
        {"host":"server-03.example.com",                   "tags":["live","tue","apt"],   "bastion": "jumphost.example.com" }
    ]
}

Comments

The serverlist.json is nearly JSON: next to plain JSON you can start a comment with # character that sets a comment up to the end of line. The # cannot be used inside you JSON data.

maintenance

This is a group to describe tags for a maintenance window.

Keys:

  • label: {string} name of the tag
  • description: {string} description tag

servers

In the subkey “servers” are array values for each server you want to use as ssh target.

Keys:

  • host: {string}
  • tags: {array}
  • bastion: {string} optional jumphost if a target is not reachable directly