https://github.com/dennyzhang/remote-commands-servers
:family: Run remote ssh commands on multiple servers
https://github.com/dennyzhang/remote-commands-servers
devops python ssh
Last synced: 11 months ago
JSON representation
:family: Run remote ssh commands on multiple servers
- Host: GitHub
- URL: https://github.com/dennyzhang/remote-commands-servers
- Owner: dennyzhang
- Created: 2017-09-05T23:43:19.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2018-07-11T22:45:44.000Z (almost 8 years ago)
- Last Synced: 2025-04-05T21:06:06.094Z (about 1 year ago)
- Topics: devops, python, ssh
- Language: Python
- Homepage: https://www.dennyzhang.com/jenkins_run_ssh
- Size: 31.3 KB
- Stars: 9
- Watchers: 5
- Forks: 14
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[](https://travis-ci.org/dennyzhang/remote-commands-servers) [](https://www.linkedin.com/in/dennyzhang001) [](https://github.com/DennyZhang) [](https://twitter.com/dennyzhang001) [](https://mywechat.slack.com/join/shared_invite/enQtMjQ0Mjg4ODk2Mjc2LTk1MTQyNTE2ZjEyNGZjZDkyOTY5ODEzMDY5ZGJkODY1OTNlYTllZTFjMGY2YzhjYjM0M2FiM2Y0OGQ5NGI3Y2U)
- File me [tickets](https://github.com/DennyZhang/remote-commands-servers/issues) or star [the repo](https://github.com/DennyZhang/remote-commands-servers)
# remote-commands-servers
Run remote ssh commands on multiple servers
You can:
1. Choose whether to run sequentially or in parallel. By default, it's sequential.
2. When sequentially, it will abort immediately if any node has failed. Customize by **--avoid_abort**.
Assumptions:
- All ssh servers accept the same username
- All ssh servers accept the same ssh private key
# remote-commands-servers usage
```
Denny: mac$ python ./remote-commands-servers.py --help
usage: remote-commands-servers.py [-h] --server_list SERVER_LIST [--command_list COMMAND_LIST] [--command_file COMMAND_FILE]
[--ssh_username SSH_USERNAME] --ssh_key_file SSH_KEY_FILE [--key_passphrase KEY_PASSPHRASE]
[--enable_parallel] [--avoid_abort]
optional arguments:
-h, --help show this help message and exit
--server_list SERVER_LIST
A list of ip-port. Separated by comma
--command_list COMMAND_LIST
A list of commands to run
--command_file COMMAND_FILE
File to host bash command. If --command_list no given, use this one
--ssh_username SSH_USERNAME
SSH username
--ssh_key_file SSH_KEY_FILE
SSH private key file. Here we assume the same key file works for all servers
--key_passphrase KEY_PASSPHRASE
Key passphrase for SSH private key file. If not given, key file is in plain text
--enable_parallel By default, it's sequential. If enabled, we will run commands in all nodes simultaneously
--avoid_abort When sequentially, whether to keep going if some nodes have failed
```
# Different Scenarios
- Paralell
```
python ./remote-commands-servers.py \
--server_list "45.33.88.175:2702, www.dennyzhang.com:23, test.dennyzhang.com:2703" \
--command_list "date && hostname" --ssh_username "root" \
--enable_parallel \
--ssh_key_file "/Users/mac/.ssh/id_rsa" --key_passphrase "mykeypass"
```
- Sequential
```
python ./remote-commands-servers.py \
--server_list "45.33.88.175:2702, www.dennyzhang.com:23, test.dennyzhang.com:2703" \
--command_list "date && hostname" --ssh_username "root" \
--ssh_key_file "/Users/mac/.ssh/id_rsa" --key_passphrase "mykeypass"
```
- Sequential, abort if any errors
```
python ./remote-commands-servers.py \
--server_list "45.33.88.175:2702, www.dennyzhang.com:23, test.dennyzhang.com:2703" \
--command_list "date; false && hostname" --ssh_username "root" \
--ssh_key_file "/Users/mac/.ssh/id_rsa" --key_passphrase "mykeypass"
```
- Sequential, avoid fast fail
```
python ./remote-commands-servers.py \
--server_list "45.33.88.175:2702, www.dennyzhang.com:23, test.dennyzhang.com:2703" \
--command_list "date; false && hostname" --ssh_username "root" \
--avoid_abort \
--ssh_key_file "/Users/mac/.ssh/id_rsa" --key_passphrase "mykeypass"
```
Code is licensed under [MIT License](https://www.dennyzhang.com/wp-content/mit_license.txt).
