multiSSH3 5.91__py3-none-any.whl → 6.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of multiSSH3 might be problematic. Click here for more details.

@@ -0,0 +1,873 @@
1
+ Metadata-Version: 2.4
2
+ Name: multiSSH3
3
+ Version: 6.2
4
+ Summary: Run commands on multiple hosts via SSH
5
+ Home-page: https://github.com/yufei-pan/multiSSH3
6
+ Author: Yufei Pan
7
+ Author-email: pan@zopyr.us
8
+ License: GPLv3+
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)
11
+ Classifier: Operating System :: POSIX :: Linux
12
+ Classifier: Operating System :: MacOS
13
+ Classifier: Operating System :: Microsoft :: Windows
14
+ Requires-Python: >=3.6
15
+ Description-Content-Type: text/markdown
16
+ Requires-Dist: argparse
17
+ Requires-Dist: ipaddress
18
+ Dynamic: author
19
+ Dynamic: author-email
20
+ Dynamic: classifier
21
+ Dynamic: description
22
+ Dynamic: description-content-type
23
+ Dynamic: home-page
24
+ Dynamic: license
25
+ Dynamic: requires-dist
26
+ Dynamic: requires-python
27
+ Dynamic: summary
28
+
29
+ # multiSSH3
30
+
31
+ ## Introduction
32
+ A script that is able to issue commands to multiple hosts while monitoring their progress.
33
+ Can be used in bash scripts for automation actions.
34
+ Also able to be imported and / or use with Flexec SSH Backend to perform cluster automation actions.
35
+
36
+ ## Install
37
+ Install via
38
+ ```bash
39
+ pip install multiSSH3
40
+ ```
41
+
42
+ multiSSH3 will be in cli available as
43
+ ```bash
44
+ mssh
45
+ mssh3
46
+ multissh
47
+ multissh3
48
+ multiSSH3
49
+ ```
50
+
51
+ ## Configuration
52
+ ### Config File Chain
53
+ multissh treat config files as definable default values.
54
+
55
+ Configed values can be inspected by simply running
56
+ ```bash
57
+ mssh -h
58
+ ```
59
+ to print the help message with current default values.
60
+
61
+ Defaults are read from the following chain map stored as json files, top ones overwrite the bottom ones.:
62
+ | `CONFIG_FILE_CHAIN` |
63
+ | ------------- |
64
+ | `./multiSSH3.config.json` |
65
+ | `~/multiSSH3.config.json` |
66
+ | `~/.multiSSH3.config.json` |
67
+ | `~/.config/multiSSH3/multiSSH3.config.json`|
68
+ | `/etc/multiSSH3.d/multiSSH3.config.json`|
69
+ | `/etc/multiSSH3.config.json`|
70
+
71
+ ### Generating / Storing Config File
72
+ To store / generate a config file with the current command line options, you can use
73
+ ```bash
74
+ mssh --store_config_file [STORE_CONFIG_FILE_PATH]
75
+ ```
76
+ > `--store_config_file [STORE_CONFIG_FILE]`<br/>
77
+ > is equivalent to <br/>
78
+ > `--generate_config_file --config_file [CONFIG_FILE]` <br/>
79
+ > and <br/>
80
+ > `--generate_config_file > [STORE_CONFIG_FILE_PATH]`.
81
+ >
82
+ >`--generate_config_file` will output to stdout if `--config_file` is not specified.
83
+
84
+ > Use `--store_config_file` without a path will store to `multiSSH3.config.json` in the current working directory.
85
+
86
+ You can modify the json file or use command line arguments to update values and store them as defaults.
87
+ ```bash
88
+ mssh --timeout 180 --store_config_file
89
+ ```
90
+ will store
91
+ ```json
92
+ ...
93
+ "DEFAULT_CLI_TIMEOUT": "180"
94
+ ...
95
+ ```
96
+ into `./multiSSH3.config.json`
97
+
98
+
99
+ > If you want to store password, it will be a plain text password in this config file. This will be better to supply it everytime as a CLI argument but you should really consider setting up public-key authentication.
100
+
101
+ >On some systems, scp / rsync will require you use public-key authentication to work.<br/>
102
+
103
+ ### SSH ControlMaster Configuration
104
+
105
+ Note: you probably want to set presistent ssh connections to speed up each connection events.
106
+
107
+ You can add the following to your `~/.ssh/config` file to enable ControlMaster with a 1 hour persistence by running
108
+
109
+ ```bash
110
+ mssh --add_control_master_config
111
+ ```
112
+
113
+ ```config
114
+ Host *
115
+ ControlMaster auto
116
+ ControlPath /run/user/%i/ssh_sockets_%C
117
+ ControlPersist 3600
118
+ ```
119
+
120
+ ## Environment Variables for Hostname Aliases
121
+
122
+ multissh3 is able to read hostname grouping / aliases from environment variables.
123
+
124
+
125
+ By default mssh reads env variables and recursive resolves them if specified with a hostname that is not be able to be resolved from `/etc/hosts`. This functions as a pseudo dns service for hostname grouping.
126
+
127
+ > Use `[0-9]`, `[0-f]`, `[a-Z]` ranges in the hostname strings for range expansion.
128
+
129
+ > Use `,` to separate multiple hostnames / hostname groups.
130
+
131
+ ### Hostname Resolution Logic
132
+
133
+ First, mssh will expand [a-b] ranges in the hostname strings.
134
+
135
+ - Check if an IPv4 range is given
136
+ - Expand using ipv4 range expansion logic.
137
+ - Return
138
+ - Check if range given is all numerical
139
+ - Expand using numerical expansion logic.
140
+ - Resolve hostnames
141
+ - Return
142
+ - Check if range given is all hex characters
143
+ - Expand using hex expansion logic.
144
+ - Resolve hostnames
145
+ - Return
146
+ - Else
147
+ - Expand using alphanumeric expansion logic.
148
+ - Resolve hostnames
149
+ - Return
150
+
151
+ When hostname need to be resolved, mssh will check in the following order:
152
+ - Return if it is an ipv4 address
153
+ - Return if hostname is in /etc/hosts
154
+ - If `-C, --no_env` is not specified and hostname is in current terminal environment variables
155
+ - Redo the whole range -> hostname resolution logic with the resolved env variable value.
156
+ - hostname is in map generated from env_file(s) specified by `--env_files ENV_FILES`
157
+ - Redo the whole range -> hostname resolution logic with the resolved env variable value.
158
+ - Lookup using `socket.gethostbyname()` to query dns server. ( Slow! )
159
+
160
+ > TLDR:
161
+ >
162
+ > ipv4 address expansion -> range expansion -> identify ipv4 -> resolve using environment variables ( if not no_env ) -> env map from env_files -> remote hostname resolution
163
+
164
+
165
+ ### Default Env Files
166
+
167
+ > Because command environment variables take precedence over env files, you can specify `-C, --no_env` or set `"DEFAULT_NO_ENV": true` in config file to disable environment variable lookup.
168
+
169
+ > Use `-ef ENV_FILE, --env_file ENV_FILE` to specify a single env file to replace the default env file lookup chain. ( Only this file will be used. )
170
+
171
+ > Use `-efs ENV_FILES, --env_files ENV_FILES` to append files to the end of the default env file lookup chain. ( Files will be loaded first to last. )
172
+
173
+
174
+ | `DEFAULT_ENV_FILES` |
175
+ | ------------- |
176
+ | `/etc/profile.d/hosts.sh` |
177
+ | `~/.bashrc` |
178
+ | `~/.zshrc` |
179
+ | `~/host.env` |
180
+ | `~/hosts.env` |
181
+ | `.env` |
182
+ | `host.env` |
183
+ | `hosts.env` |
184
+
185
+ Later files take precedence over earlier files.
186
+
187
+ ### Example Env Hostname File
188
+
189
+ An example hostname alias file will look like:
190
+ ```bash
191
+ us_east='100.100.0.1-3,us_east_prod_[1-5]'
192
+ us_central=""
193
+ us_west="100.101.0.1-2,us_west_prod_[a-c]_[1-3]"
194
+ us="$us_east,$us_central,$us_west"
195
+ asia="100.90.0-1.1-9"
196
+ eu=''
197
+ rhel8="$asia,$us_east"
198
+ all="$us,$asia,$eu"
199
+ ```
200
+ ( You can use bash replacements for grouping. )
201
+
202
+ ### Hostname Range Expansion
203
+
204
+ mssh is also able to recognize ip blocks / number blocks / hex blocks / character blocks directly.
205
+
206
+ For example:
207
+ ```bash
208
+ mssh testrig[1-10] lsblk
209
+ mssh ww[a-c],10.100.0.* 'cat /etc/fstab' 'sed -i "/lustre/d' /etc/fstab' 'cat /etc/fstab'
210
+ ```
211
+
212
+ ## Misc Features
213
+
214
+ ### Interactive Inputs
215
+
216
+ It also supports interactive inputs. ( and able to async boardcast to all supplied hosts )
217
+ ```bash
218
+ mssh www bash
219
+ ```
220
+ mssh cache all inputs and send them to all hosts when they are ready to receive inputs.
221
+
222
+ ### Curses Window Size Control
223
+
224
+ By default, it will try to fit everything inside your window.
225
+ ```bash
226
+ DEFAULT_WINDOW_WIDTH = 40
227
+ DEFAULT_WINDOW_HEIGHT = 1
228
+ ```
229
+ While leaving minimum 40 characters / 1 line for each host display by default. You can modify this by using `-ww WINDOW_WIDTH, --window_width WINDOW_WIDTH` and `-wh WINDOW_HEIGHT, --window_height WINDOW_HEIGHT`.
230
+
231
+ > It is also possible to modify the window size within curses display by pressing keys:
232
+ > ```
233
+ > ? : Toggle Help Menu
234
+ > _ or + : Change window hight
235
+ > { or } : Change window width
236
+ > < or > : Change host index
237
+ > |(pipe) : Toggle single host
238
+ > Ctrl+D : Exit
239
+ > Ctrl+R : Force refresh
240
+ > ↑ or ↓ : Navigate history
241
+ > ← or → : Move cursor
242
+ > PgUp/Dn : Scroll history by 5
243
+ > Home/End: Jump cursor
244
+ > Esc : Clear line
245
+ > ```
246
+ > You can also toggle this help in curses by pressing `?` or `F1`.
247
+
248
+ ### Command String Replacement
249
+
250
+ mssh will replace some magic strings in the command string with host specific values.
251
+
252
+ | Magic String | Description |
253
+ | ------------- | ------------------------------------ |
254
+ | `#HOST#` | Replaced with the expanded name /IP |
255
+ | `#HOSTNAME#` | Replaced with the expanded name / IP |
256
+ | `#USER#` | Replaced with the username |
257
+ | `#USERNAME#` | Replaced with the username |
258
+ | `#ID#` | Replaced with the ID of the host obj |
259
+ | `#I# ` | Replaced with the index of the host |
260
+ | `#PASSWD#` | Replaced with the password |
261
+ | `#PASSWORD#` | Replaced with the password |
262
+ | `#UUID#` | Replaced with the UUID of the host |
263
+ | `#RESOLVEDNAME#`| Replaced with the resolved name |
264
+ | `#IP#` | Replaced with the resolved IP |
265
+
266
+ > Note: `#HOST#` and `#HOSTNAME#` are the supplied hostname / ip before any resolution.
267
+
268
+ > Note: Resolved name is the IP / Hostname with user appended and ip prefix applied. This is what got used to connect to the host.
269
+
270
+ ## Options
271
+
272
+ Here details the options for multiSSH3 6.02 @ 2025-11-10
273
+
274
+ ### `-u, --username USERNAME` | _`DEFAULT_USERNAME`_
275
+ - You can specify the username for all hosts using this option and / or specifying username@hostname per host in the host list.
276
+
277
+ ### `-p, --password PASSWORD` | _`DEFAULT_PASSWORD`_
278
+ - You can specify the password for all hosts using this option. Although it is recommended to use SSH keys / store password in config file for authentication.
279
+
280
+ ### `-k, --key, --identity [KEY]` | _`DEFAULT_IDENTITY_FILE`_
281
+ - You can specify the identity file or folder to use for public key authentication. If a folder is specified, it will search for a key file inside the folder.
282
+ - This option implies `--use_key`.
283
+ - If this option is not specified but `--use_key` is specified, it will search for identity files in `DEFAULT_IDENTITY_FILE`.
284
+ - If no value is specified, it will search `DEFAULT_SSH_KEY_SEARCH_PATH`.
285
+
286
+ ### `-uk, --use_key` | _`DEFAULT_USE_KEY`_
287
+ - Attempt to use public key authentication to connect to the hosts.
288
+ - Will search for identity file in `DEFAULT_IDENTITY_FILE` if `--identity` is not specified.
289
+
290
+ ### `-ea, --extraargs EXTRAARGS` | _`DEFAULT_EXTRA_ARGS`_
291
+ - Extra arguments to pass to the ssh / rsync / scp command. Put in one string for multiple arguments.
292
+ - Example:
293
+ ```bash
294
+ mssh -ea="--delete" -f ./data/ allServers /tmp/data/
295
+ ```
296
+
297
+ ### `-11, --oneonone` | _`DEFAULT_ONE_ON_ONE`_
298
+ - Run commands in one-on-one mode, where each command corresponds to each host, front to back.
299
+ - If command list length is not equal to expanded host list length, an error will be raised.
300
+
301
+ ### `-f, --file FILE` | None
302
+ - The file to be copied to the hosts. Use -f multiple times to copy multiple files.
303
+ - When file is specified, the command(s) will be treated as the destination path(s) on the remote hosts.
304
+ - By default, rsync will be tried first on linux, scp will be used on windows or if rsync have failed to on linux.
305
+
306
+ ### `-s, -fs, --file_sync [FILE_SYNC]` | _`DEFAULT_FILE_SYNC`_
307
+ - Operate in file sync mode, sync path in `<COMMANDS>` from this machine to `<HOSTS>`.
308
+ - Treat `--file <FILE>` and `<COMMANDS>` both as source and source
309
+ - Destination path will be inferred from source path ( Absolute Path ).
310
+ - `-fs` can also be followed by a path, a syntaxic sugar for specifying the path after the option.
311
+ - Example:
312
+ ```bash
313
+ mssh -fs -- allServers ./data/ # is equivalent to
314
+ mssh -fs ./data/ allServers # is equivalent to
315
+ mssh -fs -f ./data/ allServers # is equivalent to
316
+ # if the cwd is at /tmp,
317
+ mssh -f ./data/ allServers /tmp/data/
318
+ ```
319
+
320
+ ### `-W, --scp` | _`DEFAULT_SCP`_
321
+ - Use scp for copying files by default instead of trying rsync.
322
+ - Can speed up operation if we know rsync will not be available on remote hosts.
323
+
324
+ ### `-G, -gm, --gather_mode` | False
325
+ - Gather files from the hosts instead of sending files to the hosts.
326
+ - Will send remote files specified in `<FILE>` to local path specified in `<COMMANDS>`.
327
+ - Likely you will need to combine with the [Command String Replacement](#command-string-replacement) feature to let each host transfer to a different local path.
328
+
329
+ ### `-t, --timeout TIMEOUT` | _`DEFAULT_CLI_TIMEOUT`_
330
+ - Timeout for each command in seconds.
331
+ - When using 0, timeout is disabled.
332
+ - For CLI interface, will use `DEFAULT_CLI_TIMEOUT` as default.
333
+ - For module interface, will use `DEFAULT_TIMEOUT` as default.
334
+
335
+ ### `-T, --use_script_timeout` | False
336
+ - In CLI, use `DEFAULT_TIMEOUT` as timeout value instead of `DEFAULT_CLI_TIMEOUT`.
337
+ - This is to emulate the module interface behavior as if using in a script.
338
+
339
+ ### `-r, --repeat REPEAT` | _`DEFAULT_REPEAT`_
340
+ - Repeat the commands for a number of times.
341
+ - Commands will be repeated in sequence for the specified number of times.
342
+ - Between repeats, it will wait for `--interval INTERVAL` seconds.
343
+
344
+ ### `-i, --interval INTERVAL` | _`DEFAULT_INTERVAL`_
345
+ - Interval between command repeats in seconds.
346
+ - Only effective when `REPEAT` is greater than 1.
347
+ - Note: will wait for `INTERVAL` seconds before first run if `REPEAT` is greater than 1.
348
+
349
+ ### `-M, --ipmi` | _`DEFAULT_IPMI`_
350
+ - Use ipmitool to run the command instead of ssh.
351
+ - Will strip `ipmitool` from the start of the command if it is present.
352
+ - Will replace the host's resolved IP address header with `DEFAULT_IPMI_INTERFACE_IP_PREFIX` in this mode
353
+ - Ex: `10.0.0.1` + `DEFAULT_IPMI_INTERFACE_IP_PREFIX='192.168'` -> `192.168.0.1`
354
+ - Will retry using original ip and run `ipmitool` over ssh if ipmi connection had failed. ( Will append ipmitool to the command if not present )
355
+
356
+ ### `-mpre, --ipmi_interface_ip_prefix IPMI_INTERFACE_IP_PREFIX` | _`DEFAULT_IPMI_INTERFACE_IP_PREFIX`_
357
+ - The prefix of the IPMI interfaces. Will replace the resolved IP address with the given prefix when using ipmi mode.
358
+ - This will take precedence over `INTERFACE_IP_PREFIX` when in ipmi mode.
359
+ - Ex: `10.0.0.1` + `-mpre '192.168'` -> `192.168.0.1`
360
+
361
+ ### `-pre, --interface_ip_prefix INTERFACE_IP_PREFIX` | _`DEFAULT_INTERFACE_IP_PREFIX`_
362
+ - The prefix of the for the interfaces. Will replace the resolved IP address with the given prefix when connecting to the host.
363
+ - Will prioritize `IPMI_INTERFACE_IP_PREFIX` if it exists when in ipmi mode.
364
+ - Ex: `10.0.0.1` + `-pre '172.30'` -> `172.30.0.1`
365
+
366
+ ### `-iu, --ipmi_username IPMI_USERNAME` | _`DEFAULT_IPMI_USERNAME`_
367
+ - The username to use to connect to the hosts via ipmi.
368
+ - This will be used when `--ipmi` is specified.
369
+ - If this is not specified, `DEFAULT_USERNAME` will be used in ipmi mode.
370
+
371
+ ### `-ip, --ipmi_password IPMI_PASSWORD` | _`DEFAULT_IPMI_PASSWORD`_
372
+ - The password to use to connect to the hosts via ipmi.
373
+ - This will be used when `--ipmi` is specified.
374
+ - If this is not specified, `DEFAULT_PASSWORD` will be used in ipmi mode.
375
+
376
+ ### `-S, -q, -nw, --no_watch` | _`DEFAULT_NO_WATCH`_
377
+ - Disable the curses terminal display and only print the output.
378
+ - Note this will not be 'quiet mode' traditionally, please use `-Q, -no, --quiet, --no_output` to disable output.
379
+ - Useful in scripting to reduce runtime and terminal flashing.
380
+
381
+ ### `-ww, --window_width WINDOW_WIDTH` | _`DEFAULT_WINDOW_WIDTH`_
382
+ - The minimum character length of the curses window.
383
+ - Default is 40 characters.
384
+ - Will try to fit as many hosts as possible in the terminal window while leaving at least this many characters for each host display.
385
+ - You can modify this value in curses display by pressing `_` or `+`.
386
+
387
+ ### `-wh, --window_height WINDOW_HEIGHT` | _`DEFAULT_WINDOW_HEIGHT`_
388
+ - The minimum line height of the curses window.
389
+ - Default is 1 line.
390
+ - Will try to fit as many hosts as possible in the terminal window while leaving at least this many lines for each host display.
391
+ - You can modify this value in curses display by pressing `{` or `}`.
392
+ - Terminal will overflow if it is smaller than ww * wh.
393
+
394
+ ### `-B, -sw, --single_window` | _`DEFAULT_SINGLE_WINDOW`_
395
+ - Use a single window mode for curses display.
396
+ - This shows a single large window for a host for detailed monitoring.
397
+ - You can rotate between hosts by pressing `<` or `>` in curses display. ( also works in non single window mode )
398
+ - You can toggle single window mode in curses display by pressing `|` ( pipe ).
399
+
400
+ ### `-R, -eo, --error_only` | _`DEFAULT_ERROR_ONLY`_
401
+ - Print `Success` if all hosts returns zero.
402
+ - Only print output for the hosts that returns non-zero.
403
+ - Useful in scripting to reduce output.
404
+
405
+ ### `-Q, -no, --no_output, --quiet` | _`DEFAULT_NO_OUTPUT`_
406
+ - Do not print any output.
407
+ - Note: if using without `--no_watch`, the curses display will still be shown.
408
+ - Useful in scripting when failure is expected.
409
+ - Note: return code will still be returned correctly unless `-Z, -rz, --return_zero` is specified.
410
+
411
+ ### `-Z, -rz, --return_zero` | _`DEFAULT_RETURN_ZERO`_
412
+ - Return 0 even if there are errors.
413
+ - Useful in scripting when failure is expected and bash is set to exit when error occurs.
414
+
415
+ ### `-C, --no_env` | _`DEFAULT_NO_ENV`_
416
+ - Do not load the command line environment variables for hostname resolution.
417
+ - Only use `/etc/hosts` -> env files specified in `--env_files ENV_FILES` -> DNS for hostname resolution.
418
+ - Useful when environment variables can interfere with hostname resolution ( for example not reloading environment variables after refreshing them ).
419
+
420
+ ### `-ef, --env_file ENV_FILE` | None
421
+ - Replace the env file look up chain with this env_file. ( Still work with `--no_env` )
422
+ - Only this file will be used for env file hostname resolution.
423
+ - Useful when you want to use a specific env file for hostname resolution.
424
+
425
+ ### `-efs, --env_files ENV_FILES` | _`DEFAULT_ENV_FILES`_
426
+ - The files to load the environment variables for hostname resolution.
427
+ - Can specify multiple. Load first to last. ( Still work with `--no_env` )
428
+ - Useful when you want to add additional env files for hostname resolution.
429
+
430
+ ### `-m, --max_connections MAX_CONNECTIONS` | _`DEFAULT_MAX_CONNECTIONS`_
431
+ - The maximum number of concurrent connections to establish.
432
+ - Default is 4 * cpu_count connections.
433
+ - Useful for limiting the number of simultaneous SSH connections to avoid overwhelming the compute resources / security limits
434
+ - Note: mssh will open at least 3 files per connection. By default some linux systems will only set the ulimit -n to 1024 files. This means about 300 connections can be opened simultaneously. You can increase the ulimit -n value to allow more connections if needed.
435
+ - You will observe `Warning: The number of maximum connections {max_connections} is larger than estimated limit {estimated_limit} .....` if the max connections is larger than estimated limit.
436
+ - mssh will also throttle thread generation if the estimated limit is lower than 2 * `max_connections` to avoid hitting the file descriptor limit as python fill use some file descriptors when setting up threads.
437
+
438
+ ### `-j, --json` | _`DEFAULT_JSON_OUTPUT`_
439
+ - Output in json format.
440
+ - Will also respect `-R, -eo, --error_only` and `-Q, -no, --quiet, --no_output` options.
441
+
442
+ ### `-w, --success_hosts` | _`DEFAULT_SUCCESS_HOSTS`_
443
+ - By default, a summary of failed hosts is printed.
444
+ - Use this option to also print the hosts that succeeded in summary as well.
445
+ - Useful when you want to do something with the succeeded hosts later.
446
+ - Note: you can directly use the failed / succeeded host list string as it should be fully compatible with mssh host input.
447
+
448
+ ### `-P, -g, --greppable, --table` | _`DEFAULT_GREPPABLE_OUTPUT`_
449
+ - Output in greppable table.
450
+ - Each line contains: Hostname / Resolved Name / Return Code / Output Type/ Output
451
+ - Note a host can have multiple lines if the output contains multiple lines.
452
+ - Useful in a script if we are piping the output to a log file for later grepping.
453
+
454
+ ### `-x, -su, --skip_unreachable` | _`DEFAULT_SKIP_UNREACHABLE`_
455
+ - Skip unreachable hosts.
456
+ - Note: Timedout Hosts are considered unreachable.
457
+ - By default mssh set this to true to speed up operations on large host lists with some unreachable hosts.
458
+ - Unreachable hosts will be tried again when their timeout expires.
459
+ - mssh stores the current run unreachable hosts in memory and if `skip_unreachable` is true, it will store them in a temperary file called __{username}_multiSSH3_UNAVAILABLE_HOSTS.csv in the system temp folder.
460
+ - To force mssh to not use unreachable hosts from previous runs, you can use `-a, -nsu, --no_skip_unreachable` to set `skip_unreachable` to false.
461
+
462
+ ### `-a, -nsu, --no_skip_unreachable` | not _`DEFAULT_SKIP_UNREACHABLE`_
463
+ - Do not skip unreachable hosts.
464
+ - This forms an mutually exclusive pair with `-x, -su, --skip_unreachable`.
465
+ - This option sets `skip_unreachable` to false.
466
+
467
+ ### `-uhe, --unavailable_host_expiry UNAVAILABLE_HOST_EXPIRY` | _`DEFAULT_UNAVAILABLE_HOST_EXPIRY`_
468
+ - The expiry time in seconds for unreachable hosts stored in the temperary unavailable hosts file.
469
+ - Default is 600 seconds ( 10 minutes ).
470
+ - Note: because mssh stores a hostname: expire_time pair in the unavailable hosts file, opeartor is able to use different expiry time for different runs to control how long unreachable hosts are skipped and they will be expired at the correct time.
471
+ - Note: because mssh stores the expire time in monotonic time. In most systems, this means the expiry time will not persist across system reboots. ( and also the fact it is store in the system temp folder ) although the unavailable hosts can accidentally persist across reboots if the system is rebooted often and the `unavailable_host_expiry` is set to a very large value.
472
+
473
+ ### `-X, -sh, --skip_hosts SKIP_HOSTS` | _`DEFAULT_SKIP_HOSTS`_
474
+ - A comma separated list of hosts to skip.
475
+ - This field will be expanded in the same way as the host list.
476
+ - Useful when you want to skip some hosts temporarily without modifying the host list.
477
+
478
+ ### `--generate_config_file` | False
479
+ - Generate a config file with the current command line options.
480
+ - Outputs to stdout if `--config_file` is not specified.
481
+
482
+ ### `--config_file [CONFIG_FILE]` | None
483
+ - Additional config file path to load options from.
484
+ - Will be loaded last thus overwriting other config file values.
485
+ - Use without value to use `multiSSH3.config.json` in the current working directory.
486
+ - Also used with `--generate_config_file` to specify output path.
487
+
488
+ ### `--store_config_file [STORE_CONFIG_FILE]` | None
489
+ - Store the current command line options to a config file.
490
+ - Equivalent to `--generate_config_file --config_file [STORE_CONFIG_FILE]`
491
+ - Outputs to `multiSSH3.config.json` in the current working directory if no path is specified.
492
+
493
+ ### `--debug` | False
494
+ - Enable debug mode.
495
+ - Print host specific debug messages to hosts's stderr.
496
+
497
+ ### `-ci, --copy_id` | False
498
+ - `copy_id` mode, use `ssh-copy-id` to copy public key to the hosts.
499
+ - Will use the identity file if specified in `-k, --key, --identity [KEY]`
500
+ - Will respect `-u, --username` and `-p, --password` options for username and password. ( password will need `sshpass` to be installed, or it will prompt for password interactively )
501
+
502
+ ### `-I, -nh, --no_history` | _`DEFAULT_NO_HISTORY`_
503
+ - Do not store command history.
504
+ - By default, mssh store command history in `HISTORY_FILE`.
505
+ - Useful in scripts when you do not want to store command history.
506
+
507
+ ### `-hf, --history_file HISTORY_FILE` | _`DEFAULT_HISTORY_FILE`_
508
+ - The file to store command history.
509
+ - By default, mssh store command history in `~/.mssh_history`.
510
+ - The history file is a TSV ( tab separated values ) file with each line containing: timestamp, mssh_path, options, hosts, commands.
511
+
512
+ ### `--script` | False
513
+ - Script mode, syntatic sugar for `-SCRIPT` or `--no_watch --skip_unreachable --no_env --no_history --greppable --error_only`.
514
+ - Useful when using mssh in shell scripts.
515
+
516
+ ### `-e, --encoding ENCODING` | _`DEFAULT_ENCODING`_
517
+ - The encoding to use for decoding the output from the hosts.
518
+ - Default is `utf-8`.
519
+
520
+ ### `-dt, --diff_display_threshold DIFF_DISPLAY_THRESHOLD` | _`DEFAULT_DIFF_DISPLAY_THRESHOLD`_
521
+ - The threshold of different lines to total lines ratio to trigger N-body diff display mode.
522
+ - When the output difference ratio exceeds this threshold, mssh will display the diff between outputs instead of the full outputs.
523
+ - Useful when the outputs are large and mostly similar.
524
+ - Set to 1.0 to always use diff display mode.
525
+ - Set to 0.0 to never use diff display mode.
526
+ - Note: This uses custom N-body diff algorithm. Uses some memory.
527
+
528
+ ### `--force_truecolor` | _`DEFAULT_FORCE_TRUECOLOR`_
529
+ - Force enable truecolor support in curses display.
530
+ - Useful when your terminal supports truecolor but is not detected correctly.
531
+
532
+ ### `--add_control_master_config` | False
533
+ - Add ControlMaster configuration to your `~/.ssh/config` file to enable persistent ssh connections.
534
+ - This will help speed up connections to multiple hosts.
535
+ - The configuration added is:
536
+ ```config
537
+ Host *
538
+ ControlMaster auto
539
+ ControlPath /run/user/%i/ssh_sockets_%C
540
+ ControlPersist 3600
541
+ ```
542
+
543
+ ### `-V, --version` | False
544
+ - Print the version of multiSSH3 and exit.
545
+ - Will also print the found system binary for calling when setting up connections.
546
+
547
+ ## Usage
548
+
549
+ Use ```mssh --help``` for more info.
550
+
551
+ Below is a sample help message output from multiSSH3 6.02 @ 2025-11-10
552
+
553
+ ```bash
554
+ $ mssh -h
555
+ usage: multiSSH3.py [-h] [-u USERNAME] [-p PASSWORD] [-k [IDENTITY_FILE]] [-uk] [-ea EXTRAARGS] [-11] [-f FILE] [-s [FILE_SYNC]] [-W] [-G] [-t TIMEOUT] [-T] [-r REPEAT] [-i INTERVAL] [-M] [-mpre IPMI_INTERFACE_IP_PREFIX] [-pre INTERFACE_IP_PREFIX] [-iu IPMI_USERNAME] [-ip IPMI_PASSWORD] [-S] [-ww WINDOW_WIDTH] [-wh WINDOW_HEIGHT] [-B] [-R] [-Q] [-Z] [-C] [-ef ENV_FILE] [-efs ENV_FILES] [-m MAX_CONNECTIONS] [-j] [-w] [-P] [-x | -a] [-uhe UNAVAILABLE_HOST_EXPIRY] [-X SKIP_HOSTS] [--generate_config_file] [--config_file [CONFIG_FILE]] [--store_config_file [STORE_CONFIG_FILE]] [--debug] [-ci] [-I] [-hf HISTORY_FILE] [--script] [-e ENCODING] [-dt DIFF_DISPLAY_THRESHOLD] [--force_truecolor] [--add_control_master_config] [-V] [hosts] [commands ...]
556
+
557
+ Run a command on multiple hosts, Use #HOST# or #HOSTNAME# to replace the host name in the command.
558
+
559
+ positional arguments:
560
+ hosts Hosts to run the command on, use "," to seperate hosts. (default: all)
561
+ commands the command to run on the hosts / the destination of the files #HOST# or #HOSTNAME# will be replaced with the host name.
562
+
563
+ options:
564
+ -h, --help show this help message and exit
565
+ -u, --username USERNAME
566
+ The general username to use to connect to the hosts. Will get overwrote by individual username@host if specified. (default: None)
567
+ -p, --password PASSWORD
568
+ The password to use to connect to the hosts, (default: )
569
+ -k, --identity_file, --key, --identity [IDENTITY_FILE]
570
+ The identity file to use to connect to the hosts. Implies --use_key. Specify a folder for program to search for a key. Use option without value to use ~/.ssh/ (default: None)
571
+ -uk, --use_key Attempt to use public key file to connect to the hosts. (default: False)
572
+ -ea, --extraargs EXTRAARGS
573
+ Extra arguments to pass to the ssh / rsync / scp command. Put in one string for multiple arguments.Use "=" ! Ex. -ea="--delete" (default: None)
574
+ -11, --oneonone Run one corresponding command on each host. (default: False)
575
+ -f, --file FILE The file to be copied to the hosts. Use -f multiple times to copy multiple files
576
+ -s, -fs, --file_sync [FILE_SYNC]
577
+ Operate in file sync mode, sync path in <COMMANDS> from this machine to <HOSTS>. Treat --file <FILE> and <COMMANDS> both as source and source and destination will be the same in this mode. Infer destination from source path. (default: False)
578
+ -W, --scp Use scp for copying files instead of rsync. Need to use this on windows. (default: False)
579
+ -G, -gm, --gather_mode
580
+ Gather files from the hosts instead of sending files to the hosts. Will send remote files specified in <FILE> to local path specified in <COMMANDS> (default: False)
581
+ -t, --timeout TIMEOUT
582
+ Timeout for each command in seconds. Set default value via DEFAULT_CLI_TIMEOUT in config file. Use 0 for disabling timeout. (default: 0)
583
+ -T, --use_script_timeout
584
+ Use shortened timeout suitable to use in a script. Set value via DEFAULT_TIMEOUT field in config file. (current: 50)
585
+ -r, --repeat REPEAT Repeat the command for a number of times (default: 1)
586
+ -i, --interval INTERVAL
587
+ Interval between repeats in seconds (default: 0)
588
+ -M, --ipmi Use ipmitool to run the command. (default: False)
589
+ -mpre, --ipmi_interface_ip_prefix IPMI_INTERFACE_IP_PREFIX
590
+ The prefix of the IPMI interfaces (default: )
591
+ -pre, --interface_ip_prefix INTERFACE_IP_PREFIX
592
+ The prefix of the for the interfaces (default: None)
593
+ -iu, --ipmi_username IPMI_USERNAME
594
+ The username to use to connect to the hosts via ipmi. (default: ADMIN)
595
+ -ip, --ipmi_password IPMI_PASSWORD
596
+ The password to use to connect to the hosts via ipmi. (default: )
597
+ -S, -q, -nw, --no_watch
598
+ Quiet mode, no curses watch, only print the output. (default: False)
599
+ -ww, --window_width WINDOW_WIDTH
600
+ The minimum character length of the curses window. (default: 40)
601
+ -wh, --window_height WINDOW_HEIGHT
602
+ The minimum line height of the curses window. (default: 1)
603
+ -B, -sw, --single_window
604
+ Use a single window for all hosts. (default: False)
605
+ -R, -eo, --error_only
606
+ Only print the error output. (default: False)
607
+ -Q, -no, --no_output, --quiet
608
+ Do not print the output. (default: False)
609
+ -Z, -rz, --return_zero
610
+ Return 0 even if there are errors. (default: False)
611
+ -C, --no_env Do not load the command line environment variables. (default: False)
612
+ -ef, --env_file ENV_FILE
613
+ Replace the env file look up chain with this env_file. ( Still work with --no_env ) (default: None)
614
+ -efs, --env_files ENV_FILES
615
+ The files to load the mssh file based environment variables from. Can specify multiple. Load first to last. ( Still work with --no_env ) (default: ['/etc/profile.d/hosts.sh', '~/.bashrc', '~/.zshrc', '~/host.env', '~/hosts.env', '.env', 'host.env', 'hosts.env'])
616
+ -m, --max_connections MAX_CONNECTIONS
617
+ Max number of connections to use (default: 4 * cpu_count)
618
+ -j, --json Output in json format. (default: False)
619
+ -w, --success_hosts Output the hosts that succeeded in summary as well. (default: False)
620
+ -P, -g, --greppable, --table
621
+ Output in greppable table. (default: False)
622
+ -x, -su, --skip_unreachable
623
+ Skip unreachable hosts. Note: Timedout Hosts are considered unreachable. Note: multiple command sequence will still auto skip unreachable hosts. (default: True)
624
+ -a, -nsu, --no_skip_unreachable
625
+ Do not skip unreachable hosts. Note: Timedout Hosts are considered unreachable. Note: multiple command sequence will still auto skip unreachable hosts. (default: False)
626
+ -uhe, --unavailable_host_expiry UNAVAILABLE_HOST_EXPIRY
627
+ Time in seconds to expire the unavailable hosts (default: 600)
628
+ -X, -sh, --skip_hosts SKIP_HOSTS
629
+ Skip the hosts in the list. (default: None)
630
+ --generate_config_file
631
+ Store / generate the default config file from command line argument and current config at --config_file / stdout
632
+ --config_file [CONFIG_FILE]
633
+ Additional config file to use, will pioritize over config chains. When using with store_config_file, will store the resulting config file at this location. Use without a path will use multiSSH3.config.json
634
+ --store_config_file [STORE_CONFIG_FILE]
635
+ Store the default config file from command line argument and current config. Same as --store_config_file --config_file=<path>
636
+ --debug Print debug information
637
+ -ci, --copy_id Copy the ssh id to the hosts
638
+ -I, -nh, --no_history
639
+ Do not record the command to history. Default: False
640
+ -hf, --history_file HISTORY_FILE
641
+ The file to store the history. (default: ~/.mssh_history)
642
+ --script Run the command in script mode, short for -SCRIPT or --no_watch --skip_unreachable --no_env --no_history --greppable --error_only
643
+ -e, --encoding ENCODING
644
+ The encoding to use for the output. (default: utf-8)
645
+ -dt, --diff_display_threshold DIFF_DISPLAY_THRESHOLD
646
+ The threshold of lines to display the diff when files differ. {0-1} Set to 0 to always display the diff. Set to 1 to disable diff. (Only merge same) (default: 0.6)
647
+ --force_truecolor Force truecolor output even when not in a truecolor terminal. (default: False)
648
+ --add_control_master_config
649
+ Add ControlMaster configuration to ~/.ssh/config to speed up multiple connections to the same host.
650
+ -V, --version show program's version number and exit
651
+ ```
652
+ Note: The default values can be modified / updated in the [Config file](#config).
653
+
654
+ ## Importing as a Module
655
+
656
+ You can also import multiSSH3 as a module in your python scripts.
657
+
658
+
659
+ ### Host Object
660
+ The `Host` object represents a host and its command execution state. The main execution function `run_command_on_hosts` returns a list of `Host` objects.
661
+
662
+ ```python
663
+ class Host:
664
+ def __init__(self, name, command, files = None,ipmi = False,interface_ip_prefix = None,scp=False,extraargs=None,gatherMode=False,identity_file=None,shell=False,i = -1,uuid=uuid.uuid4(),ip = None):
665
+ self.name = name # the name of the host (hostname or IP address)
666
+ self.command = command # the command to run on the host
667
+ self.returncode = None # the return code of the command
668
+ self.output = [] # the output of the command for curses
669
+ self.stdout = [] # the stdout of the command
670
+ self.stderr = [] # the stderr of the command
671
+ self.lineNumToPrintSet = set() # line numbers to reprint
672
+ self.lastUpdateTime = time.monotonic() # the last time the output was updated
673
+ self.lastPrintedUpdateTime = 0 # the last time the output was printed
674
+ self.files = files # the files to be copied to the host
675
+ self.ipmi = ipmi # whether to use ipmi to connect to the host
676
+ self.shell = shell # whether to use shell to run the command
677
+ self.interface_ip_prefix = interface_ip_prefix # the prefix of the ip address of the interface to be used to connect to the host
678
+ self.scp = scp # whether to use scp to copy files to the host
679
+ self.gatherMode = gatherMode # whether the host is in gather mode
680
+ self.extraargs = extraargs # extra arguments to be passed to ssh
681
+ self.resolvedName = None # the resolved IP address of the host
682
+ # also store a globally unique integer i from 0
683
+ self.i = i if i != -1 else _get_i()
684
+ self.uuid = uuid
685
+ self.identity_file = identity_file
686
+ self.ip = ip if ip else getIP(name)
687
+ self.current_color_pair = [-1, -1, 1]
688
+ self.output_buffer = io.BytesIO()
689
+ self.stdout_buffer = io.BytesIO()
690
+ self.stderr_buffer = io.BytesIO()
691
+ self.thread = None
692
+ ```
693
+
694
+ ### Example:
695
+
696
+ ```python
697
+ import multiSSH3
698
+ ethReachableHosts = multiSSH3.run_command_on_hosts(nodesToCheck,['echo hi'],returnUnfinished = True) # returnUnfinished will return the host objects immediately without waiting for all hosts to finish.
699
+ ipmiReachableHosts = multiSSH3.run_command_on_hosts(nodesToCheck,['power status'], timeout = timeout, ipmi=True, password=password, skipUnreachable=False) # ipmi command
700
+ # You can use blocks like the following block to wait on a specific host list to finish ( That does respect timeout even if the host is hanging )
701
+ # Following block also implement an exponential backoff.
702
+ sleep_interval = 0.0001
703
+ while any([host.returncode is None for host in ethReachableHosts]):
704
+ time.sleep(sleep_interval) # avoid busy-waiting
705
+ if sleep_interval < 0.01:
706
+ sleep_interval *= 1.1
707
+ # You can also use join_threads to wait on all running threads ( including timedout hanging threads )
708
+ multiSSH3.join_threads()
709
+ ...
710
+ ```
711
+
712
+ ### `run_command_on_hosts` Function
713
+
714
+ The run_command_on_hosts function includes almost all the options available in the CLI. ( some options modify the [global variables](#all-changable-config-options--global-variables-) and can be set before calling the function. )
715
+
716
+ ```python
717
+ def run_command_on_hosts(hosts = DEFAULT_HOSTS,commands = None,oneonone = DEFAULT_ONE_ON_ONE, timeout = DEFAULT_TIMEOUT,password = DEFAULT_PASSWORD,no_watch = DEFAULT_NO_WATCH,json = DEFAULT_JSON_MODE,called = _DEFAULT_CALLED,max_connections=DEFAULT_MAX_CONNECTIONS,file = None,ipmi = DEFAULT_IPMI,interface_ip_prefix = DEFAULT_INTERFACE_IP_PREFIX,returnUnfinished = _DEFAULT_RETURN_UNFINISHED,scp=DEFAULT_SCP,gather_mode = False,username=DEFAULT_USERNAME,extraargs=DEFAULT_EXTRA_ARGS,skipUnreachable=DEFAULT_SKIP_UNREACHABLE,no_env=DEFAULT_NO_ENV,greppable=DEFAULT_GREPPABLE_MODE,willUpdateUnreachableHosts=_DEFAULT_UPDATE_UNREACHABLE_HOSTS,no_start=_DEFAULT_NO_START,skip_hosts = DEFAULT_SKIP_HOSTS, window_width = DEFAULT_WINDOW_WIDTH, window_height = DEFAULT_WINDOW_HEIGHT,single_window = DEFAULT_SINGLE_WINDOW,file_sync = False,error_only = DEFAULT_ERROR_ONLY,quiet = False,identity_file = DEFAULT_IDENTITY_FILE,copy_id = False, unavailable_host_expiry = DEFAULT_UNAVAILABLE_HOST_EXPIRY,no_history = True,history_file = DEFAULT_HISTORY_FILE,
718
+ ):
719
+ """
720
+ Run commands on multiple hosts via SSH or IPMI.
721
+
722
+ Parameters:
723
+ hosts (str or iterable): Hosts to run the command on. Can be a string (comma/space-separated) or iterable. Default: DEFAULT_HOSTS.
724
+ commands (list or None): List of commands to run on the hosts. If files are used, defines the destination. Default: None.
725
+ oneonone (bool): If True, run each command on the corresponding host (1:1 mapping). Default: DEFAULT_ONE_ON_ONE.
726
+ timeout (int): Timeout for each command in seconds. Default: DEFAULT_TIMEOUT.
727
+ password (str): Password for SSH/IPMI authentication. Default: DEFAULT_PASSWORD.
728
+ no_watch (bool): If True, do not use curses TUI; just print output. Default: DEFAULT_NO_WATCH.
729
+ json (bool): If True, output results in JSON format. Default: DEFAULT_JSON_MODE.
730
+ called (bool): If True, function is called programmatically (not CLI). Default: _DEFAULT_CALLED.
731
+ max_connections (int): Maximum concurrent SSH sessions. Default: 4 * os.cpu_count().
732
+ file (list or None): Files to copy to hosts. Default: None.
733
+ ipmi (bool): Use IPMI instead of SSH. Default: DEFAULT_IPMI.
734
+ interface_ip_prefix (str or None): Override IP prefix for host connection. Default: DEFAULT_INTERFACE_IP_PREFIX.
735
+ returnUnfinished (bool): If True, return hosts even if not finished. Default: _DEFAULT_RETURN_UNFINISHED.
736
+ scp (bool): Use scp for file transfer (instead of rsync). Default: DEFAULT_SCP.
737
+ gather_mode (bool): Gather files from hosts (pull mode). Default: False.
738
+ username (str or None): Username for SSH/IPMI. Default: DEFAULT_USERNAME.
739
+ extraargs (str or list or None): Extra args for SSH/SCP/rsync. Default: DEFAULT_EXTRA_ARGS.
740
+ skipUnreachable (bool): Skip hosts marked as unreachable. Default: DEFAULT_SKIP_UNREACHABLE.
741
+ no_env (bool): Do not load environment variables from shell. Default: DEFAULT_NO_ENV.
742
+ greppable (bool): Output in greppable table format. Default: DEFAULT_GREPPABLE_MODE.
743
+ willUpdateUnreachableHosts (bool): Update global unreachable hosts file. Default: _DEFAULT_UPDATE_UNREACHABLE_HOSTS.
744
+ no_start (bool): If True, return Host objects without running commands. Default: _DEFAULT_NO_START.
745
+ skip_hosts (str or None): Hosts to skip. Default: DEFAULT_SKIP_HOSTS.
746
+ window_width (int): Minimum width per curses window. Default: DEFAULT_WINDOW_WIDTH.
747
+ window_height (int): Minimum height per curses window. Default: DEFAULT_WINDOW_HEIGHT.
748
+ single_window (bool): Use a single curses window for all hosts. Default: DEFAULT_SINGLE_WINDOW.
749
+ file_sync (bool): Enable file sync mode (sync directories). Default: DEFAULT_FILE_SYNC.
750
+ error_only (bool): Only print error output. Default: DEFAULT_ERROR_ONLY.
751
+ quiet (bool): Suppress all output (overrides other output options). Default: False.
752
+ identity_file (str or None): SSH identity file. Default: DEFAULT_IDENTITY_FILE.
753
+ copy_id (bool): Use ssh-copy-id to copy public key to hosts. Default: False.
754
+ unavailable_host_expiry (int): Seconds to keep hosts marked as unavailable. Default: DEFAULT_UNAVAILABLE_HOST_EXPIRY.
755
+ no_history (bool): Do not record command history. Default: True.
756
+ history_file (str): File to store command history. Default: DEFAULT_HISTORY_FILE.
757
+
758
+ Returns:
759
+ list: List of Host objects representing each host/command run.
760
+ """
761
+ ```
762
+
763
+ ## All Changable Config Options ( Global Variables )
764
+
765
+ Update these values in the config file to change the default behavior of multiSSH3.
766
+
767
+ > Values with leading `_` will not be included in the config file generated by mssh but are respected when set in the config file.
768
+
769
+ ```python
770
+ AUTHOR = 'Yufei Pan'
771
+ AUTHOR_EMAIL = 'pan@zopyr.us'
772
+ DEFAULT_HOSTS = 'all'
773
+ DEFAULT_USERNAME = None
774
+ DEFAULT_PASSWORD = ''
775
+ DEFAULT_IDENTITY_FILE = None
776
+ DEFAULT_SSH_KEY_SEARCH_PATH = '~/.ssh/'
777
+ DEFAULT_USE_KEY = False
778
+ DEFAULT_EXTRA_ARGS = None
779
+ DEFAULT_ONE_ON_ONE = False
780
+ DEFAULT_SCP = False
781
+ DEFAULT_FILE_SYNC = False
782
+ DEFAULT_TIMEOUT = 50
783
+ DEFAULT_CLI_TIMEOUT = 0
784
+ DEFAULT_UNAVAILABLE_HOST_EXPIRY = 600
785
+ DEFAULT_REPEAT = 1
786
+ DEFAULT_INTERVAL = 0
787
+ DEFAULT_IPMI = False
788
+ DEFAULT_IPMI_INTERFACE_IP_PREFIX = ''
789
+ DEFAULT_INTERFACE_IP_PREFIX = None
790
+ DEFAULT_IPMI_USERNAME = 'ADMIN'
791
+ DEFAULT_IPMI_PASSWORD = ''
792
+ DEFAULT_NO_WATCH = False
793
+ DEFAULT_WINDOW_WIDTH = 40
794
+ DEFAULT_WINDOW_HEIGHT = 1
795
+ DEFAULT_SINGLE_WINDOW = False
796
+ DEFAULT_ERROR_ONLY = False
797
+ DEFAULT_NO_OUTPUT = False
798
+ DEFAULT_RETURN_ZERO = False
799
+ DEFAULT_NO_ENV = False
800
+ DEFAULT_ENV_FILE = ''
801
+ DEFAULT_ENV_FILES = ['/etc/profile.d/hosts.sh',
802
+ '~/.bashrc',
803
+ '~/.zshrc',
804
+ '~/host.env',
805
+ '~/hosts.env',
806
+ '.env',
807
+ 'host.env',
808
+ 'hosts.env',
809
+ ]
810
+ DEFAULT_NO_HISTORY = False
811
+ DEFAULT_HISTORY_FILE = '~/.mssh_history'
812
+ DEFAULT_MAX_CONNECTIONS = 4 * os.cpu_count()
813
+ DEFAULT_JSON_MODE = False
814
+ DEFAULT_PRINT_SUCCESS_HOSTS = False
815
+ DEFAULT_GREPPABLE_MODE = False
816
+ DEFAULT_SKIP_UNREACHABLE = True
817
+ DEFAULT_SKIP_HOSTS = ''
818
+ DEFAULT_ENCODING = 'utf-8'
819
+ DEFAULT_DIFF_DISPLAY_THRESHOLD = 0.6
820
+ SSH_STRICT_HOST_KEY_CHECKING = False
821
+ FORCE_TRUECOLOR = False
822
+ ERROR_MESSAGES_TO_IGNORE = [
823
+ 'Pseudo-terminal will not be allocated because stdin is not a terminal',
824
+ 'Connection to .* closed',
825
+ 'Warning: Permanently added',
826
+ 'mux_client_request_session',
827
+ 'disabling multiplexing',
828
+ 'Killed by signal',
829
+ 'Connection reset by peer',
830
+ ]
831
+ __DEFAULT_COLOR_PALETTE = {
832
+ 'cyan': (86, 173, 188),
833
+ 'green': (114, 180, 43),
834
+ 'magenta': (140, 107, 200),
835
+ 'red': (196, 38, 94),
836
+ 'white': (227, 227, 221),
837
+ 'yellow': (179, 180, 43),
838
+ 'blue': (106, 126, 200),
839
+ 'bright_black': (102, 102, 102),
840
+ 'bright_blue': (129, 154, 255),
841
+ 'bright_cyan': (102, 217, 239),
842
+ 'bright_green': (126, 226, 46),
843
+ 'bright_magenta': (174, 129, 255),
844
+ 'bright_red': (249, 38, 114),
845
+ 'bright_white': (248, 248, 242),
846
+ 'bright_yellow': (226, 226, 46),
847
+ }
848
+ COLOR_PALETTE = __DEFAULT_COLOR_PALETTE.copy()
849
+ _DEFAULT_CALLED = True
850
+ _DEFAULT_RETURN_UNFINISHED = False
851
+ _DEFAULT_UPDATE_UNREACHABLE_HOSTS = True
852
+ _DEFAULT_NO_START = False
853
+ _etc_hosts = {}
854
+ __ERROR_MESSAGES_TO_IGNORE_REGEX =None
855
+ __DEBUG_MODE = False
856
+ ```
857
+ > Note: If color palette need to be changed, please change the `COLOR_PALETTE` values instead of the __DEFAULT_COLOR_PALETTE as if values are missing from __DEFAULT_COLOR_PALETTE, mssh may raise errors.
858
+
859
+ > When imported and calling as a module, `called` will be set to _DEFAULT_CALLED.<br/>
860
+ > When True, it sets several flags to make mssh behave better when called as a module.<br/>
861
+ > - if skipUnreachable is not set, it will skip unreachable hosts within one command call
862
+ > - Will clear global keyboard input cache
863
+ > - Will set global quiet mode to True
864
+
865
+ > `_DEFAULT_UPDATE_UNREACHABLE_HOSTS` is used to control whether to update the unreachable hosts file when mssh detects unreachable hosts.
866
+
867
+ > `_DEFAULT_NO_START` is somewhat analogous to "demo mode" where mssh will return Host objects without actually allocating and starting the execution threads. Although they still can be started using `start_run_on_hosts()` but you should really be looking for `returnUnfinished` instead for asynchronicity.
868
+
869
+ > `_etc_hosts` is a custom dict to use instead of reading /etc/hosts file for hostname resolution.
870
+
871
+ > `__ERROR_MESSAGES_TO_IGNORE_REGEX` is the compiled regex pattern for error messages to ignore. If custom defined, mssh will ignore `ERROR_MESSAGES_TO_IGNORE` and use supplied regex pattern instead.
872
+
873
+ > `__DEBUG_MODE` is used to control whether to print host thread execution debug information to its stderr.