Table of Contents
Usage
Just start multi_ssh.sh
- it will initialize a user config file with the defaults.
Without a parameter you reach the interactive mode.
It supports cli parameters too.
Interactive usage
Server menu
If you start the script, then you get a list of your servers. The list of servers is can be filtered with one or more tags. You can switch to another profile to see another set of servers.
Server list:
- Number - starting with
1
- Server - servername
- Bastion (20 chars) - jumphost to connect; it is empty if the server is connected directly
- last success - timestamp of the last execution of the set command with exitcode 0. If the field is empty the command was not executed yet. This field helps you to see if a command was executed on all servers alreadyor not.
- Running - Info for curently running job or fisnished job and the terminal window is still open. If it is empty then the job is not running
Server Bastion (20 chars) last success Running
1 www.example.com
2 db.example.com
:
Special commands:
':c' change command hostname -f
':t' change tags tue
':p' change profile iml
Enter numbers or parts of servernames. Use space as divider.
Just press return to update server infos amd running status.
>
Behind the prompt you can type an action and press Return.
Possible actions:
-
:c
change command to execute on all servers -
:t
change tags -
:p
change profile - A single number - or multiple numbers separated by space: The current commad will be started on the given host in an extra terminal window
Change command
After :c
you get a list of config/commands.txt + all commands.txt in the profile directory for the current profile config/<profile>/commands.txt
. This list helps you to pick a predefined action like maintenenace, backup, reboot, whatever.
You see the current command. In the prompt enter the new command.
Just return keeps the current command.
Hint:
Mark it with the mouse and paste it with middle mouse key.
Change tag
After :t
you get a list of all tags that are defined in your server configuration.
Enter tags to filter hosts; seprate mulitple tags with space (from given list)
Just return keeps the current tags(s).
Hint:
Mark it with the mouse and paste it with middle mouse key.
Change profile
After :p
you get a list of all configured profiles.
Enter a prfile to switch too.
Just return keeps the current tags(s).
Hint:
Mark it with the mouse and paste it with middle mouse key.
Execute the current command
In the menu enter a single number - or multiple numbers separated by space.
Prepare
The current commad will be started on the given host in an extra terminal window. The terminal to open can be configured, eg gnome-terminal or konsole.
see ../config/userconfig.sh - export MRE_TERMINAL=<appname>
A given ssh user will connect to the target host.
see ../config/userconfig.sh - export MRE_SSHUSER=<sshuser>
Execute
When the terminal window started you see starting time, the executed statement followed by the output of the command.
As long the command is running you will see TERM
in the server list.
>>>>> List of servers - Fri Nov 1 13:13:55 CET 2024
Server Bastion (20 chars) last success Running
1 www.example.com TERM
2 db.example.com
On finish
If the command is finished you get a line with finishing time and command. In the last line you see
- “OK” on exitcode 0
- “ERROR” on non zero exitcode
The finished execution is tracked in logs/returncodes.log
If the command is hostname -f
to be executed on www.example.com:
Fri Nov 1 13:13:49 CET 2024 START ssh admin@www.example.com hostname -f ...
_______________________________________________________________________________
www.example.com
_______________________________________________________________________________
Fri Nov 1 13:13:49 CET 2024 END ssh admin@www.example.com hostname -f
>>> OK >>> Press RETURN to exit
In the server list a successful execution is shown:
>>>>> List of servers - Fri Nov 1 13:14:09 CET 2024
Server Bastion (20 chars) last success Running
1 www.example.com 13:13:49
2 db.example.com
CLI usage
To see the parameters start multi_ssh.sh -h
_______________________________________________________________________________
MULTI REMOTE EXECUTION WITH SSH ______
________________________________________________________________________/ v0.18
A remote execution tool to run a command on multiple servers.
Its main usage is in interactive mode and command line parameters.
Source: <https://git-repo.iml.unibe.ch/iml-open-source/multi_ssh/>
License: GNU GPL 3.0
Docs: <https://os-docs.iml.unibe.ch/multi_ssh/>
2023-2024 Institute for Medical Education; University of Bern
SYNTAX:
multi_ssh.sh [OPTIONS] [SERVERLIST]
OPTIONS:
-c|--command [COMMAMD]
set a command for remote execution. A 2nd value
for the new command is optional. Without param
you reach an interactive mode.
Save config and exit.
-h|--help show this help and exit
-l|--list list servers
-p|--profile [PROFILE]
set a profile for network environment
-t|--tag [TAGNAME(s)]
set a tag to filter serverlist.
To set multiple tags quote it as a single string
and seperate them wih a space. Without param
you reach an interactive mode.
Save config and exit.
PARAMETERS:
The serverlist is a combination of servers that should
execute the command [hostname -f].
It can be the number of a server or a
A special item is ALL - it executes the command on all servers
Without a parameter you reach the interactive mode.
EXAMPLES:
multi_ssh.sh -c - set a new command. Enter it on the prompt
multi_ssh.sh -c "sudo reboot" - set a given command
multi_ssh.sh -t "mon live" - set filter tags "mon" and "live"
multi_ssh.sh -l - list servers that match all tags (AND condition)
multi_ssh.sh 1 2 5 - run the command on 1st, 2nd and 5th server
multi_ssh.sh monitor - run the command on the first server that matches 'monitor'