23 Commits
1.0.7 ... 1.0.9

Author SHA1 Message Date
1eb9c5c17d Added multiple -e 2023-09-07 17:40:37 +03:00
70136e9074 Improve readability 2023-09-07 16:05:38 +03:00
2334c1a8f3 Fix logging 2023-09-07 15:34:13 +03:00
da6ae2ce37 Improve readability 2023-09-07 15:33:15 +03:00
e2cc36adf1 Drop ARM build 2023-09-07 15:06:24 +03:00
080ce8984a Improve readability 2023-09-07 15:04:51 +03:00
b360e29666 Improve readability 2023-09-07 14:58:29 +03:00
1d26a9c6be ARM build 2023-09-01 00:22:15 +03:00
48e7e2a4e4 ARM build 2023-09-01 00:20:43 +03:00
aa0a4e8bd2 ARM build 2023-09-01 00:15:46 +03:00
554b68b51e ARM build 2023-09-01 00:09:38 +03:00
c206ddaef2 ARM build 2023-09-01 00:08:55 +03:00
e620348834 ARM build 2023-09-01 00:01:58 +03:00
dc1a67fe01 ARM build 2023-08-31 23:59:47 +03:00
1d208149f5 ARM build 2023-08-31 23:51:25 +03:00
093157b6ef ARM build 2023-08-31 23:49:32 +03:00
04da0fb97c Update README.md 2023-08-31 23:34:02 +03:00
967d9c0e7d Update README.md 2023-08-31 23:31:44 +03:00
eb0fd40d9f Update README.md 2023-08-31 23:31:10 +03:00
d0bbb29078 Update README.md 2023-08-31 23:30:37 +03:00
5a388853c5 Update README.md 2023-08-31 23:25:16 +03:00
41bf46c408 Update README.md 2023-08-31 23:19:26 +03:00
a2b05a7fa6 Fix 2023-08-31 23:15:26 +03:00
5 changed files with 117 additions and 43 deletions

View File

@ -67,7 +67,7 @@ jobs:
release: release:
name: Release binary name: Making New Release ^_^
needs: needs:
- build - build
- build_arch - build_arch

2
Cargo.lock generated
View File

@ -1066,7 +1066,7 @@ checksum = "436b050e76ed2903236f032a59761c1eb99e1b0aead2c257922771dab1fc8c78"
[[package]] [[package]]
name = "rexec" name = "rexec"
version = "1.0.6" version = "1.0.9"
dependencies = [ dependencies = [
"brace-expand", "brace-expand",
"clap 4.3.4", "clap 4.3.4",

View File

@ -1,6 +1,6 @@
[package] [package]
name = "rexec" name = "rexec"
version = "1.0.7" version = "1.0.9"
readme = "https://github.com/house-of-vanity/rexec#readme" readme = "https://github.com/house-of-vanity/rexec#readme"
edition = "2021" edition = "2021"
description = "Parallel SSH executor" description = "Parallel SSH executor"

View File

@ -1,14 +1,20 @@
# rexec # rexec
Parallel SSH executor in Rust. It can read servers from `~/.ssh/known_hosts` **Parallel SSH executor** in Rust with static binary. It can read servers from `~/.ssh/known_hosts`
or even expand servers from bash expanshion line `cassandra.{prod,dev}.example.com`
or even expand servers from bash expanshion line `cassandra-[1:5].{prod,dev}.example.com`
[![Rust-static-build](https://github.com/house-of-vanity/rexec/actions/workflows/release.yml/badge.svg)](https://github.com/house-of-vanity/rexec/actions/workflows/release.yml) [![Rust-static-build](https://github.com/house-of-vanity/rexec/actions/workflows/release.yml/badge.svg)](https://github.com/house-of-vanity/rexec/actions/workflows/release.yml)
---
## Usage
```shell
_|_|_|_| _| _| _|_|_|_| _|_|_|
_| _|_| _| _| _| _| _|
_|_| _|_|_| _| _|_|_| _|
_| _| _| _| _| _|
_| _|_|_|_| _| _| _|_|_|_| _|_|_|
```shell
[ab@test]$ ./rexec -k admin-gce-sc.* --help
Parallel SSH executor in Rust Parallel SSH executor in Rust
Usage: rexec [OPTIONS] --expression <EXPRESSION> --command <COMMAND> Usage: rexec [OPTIONS] --expression <EXPRESSION> --command <COMMAND>
@ -24,9 +30,44 @@ Options:
-h, --help Print help -h, --help Print help
-V, --version Print version -V, --version Print version
``` ```
---
## Examples
```shell
[ab@test]$ rexec -e 'cassandra-gce-sc-[1:3].bbs-prod.*' -u ab -c 'df -h /srv/cassandra'
[INFO ] Using string expansion to build server list.
[INFO ] Matched hosts:
[INFO ] cassandra-gce-sc-1.bbs-prod.* [35.221.18.35]
[INFO ] cassandra-gce-sc-2.bbs-prod.* [35.212.13.174]
[INFO ] cassandra-gce-sc-3.bbs-prod.* [35.211.213.123]
Continue on following 3 servers? y
[INFO ]
[INFO ] Run command on 3 servers.
[INFO ]
[INFO ] cassandra-gce-sc-2.bbs-prod.*
Code 0
STDOUT:
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/storage-cassandra 1.0T 613G 411G 60% /srv/cassandra
[INFO ] cassandra-gce-sc-1.bbs-prod.*
Code 0
STDOUT:
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/storage-cassandra 1.0T 594G 430G 59% /srv/cassandra
[INFO ] cassandra-gce-sc-3.bbs-prod.*
Code 0
STDOUT:
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/storage-cassandra 1.0T 523G 502G 52% /srv/cassandra
```
---
```shell ```shell
[ab@test debug]$ ./rexec -u ab -k -c uptime -e admin.* -f [ab@test]$ ./rexec -u ab -k -c uptime -e admin.* -f
[INFO ] Matched hosts: [INFO ] Matched hosts:
[INFO ] admin-gce-sc-1.lca-prod.** [35.211.27.195] [INFO ] admin-gce-sc-1.lca-prod.** [35.211.27.195]
[INFO ] admin-gce-sc-1.mmk-prod.** [35.211.79.202] [INFO ] admin-gce-sc-1.mmk-prod.** [35.211.79.202]
@ -36,27 +77,18 @@ Options:
[INFO ] Run command on 3 servers. [INFO ] Run command on 3 servers.
[INFO ] admin.gnb-prod.** [INFO ] admin.gnb-prod.**
Code 0 Code 0
STDOUT: STDOUT:
23:31:21 up 294 days, 14:14, 0 users, load average: 0.53, 0.64, 0.52 23:31:21 up 294 days, 14:14, 0 users, load average: 0.53, 0.64, 0.52
STDERR:
[INFO ] admin.abe-prod.** [INFO ] admin.abe-prod.**
Code 0 Code 0
STDOUT: STDOUT:
23:31:22 up 154 days, 9:24, 0 users, load average: 0.31, 0.25, 0.18 23:31:22 up 154 days, 9:24, 0 users, load average: 0.31, 0.25, 0.18
STDERR:
[INFO ] admin-gce-be-1.toy-prod.** [INFO ] admin-gce-be-1.toy-prod.**
Code 0 Code 0
STDOUT: STDOUT:
23:31:22 up 98 days, 6:20, 0 users, load average: 0.88, 0.74, 0.80 23:31:22 up 98 days, 6:20, 0 users, load average: 0.88, 0.74, 0.80
STDERR:
no server running on /tmp/tmux-1019/default
open terminal failed: not a terminal
``` ```

View File

@ -9,7 +9,6 @@ use std::process;
use clap::Parser; use clap::Parser;
use colored::*; use colored::*;
//use dialoguer::Confirm;
use dns_lookup::lookup_host; use dns_lookup::lookup_host;
use env_logger::Env; use env_logger::Env;
use itertools::Itertools; use itertools::Itertools;
@ -35,9 +34,10 @@ struct Args {
#[arg( #[arg(
short, short,
long, long,
num_args = 1..,
help = "Expression to build server list. List and range expansion are supported. Example: 'web-[1:12]-io-{prod,dev}'" help = "Expression to build server list. List and range expansion are supported. Example: 'web-[1:12]-io-{prod,dev}'"
)] )]
expression: String, expression: Vec<String>,
#[arg(short, long, help = "Command to execute on servers")] #[arg(short, long, help = "Command to execute on servers")]
command: String, command: String,
@ -157,22 +157,30 @@ fn main() {
let hosts = if args.known_hosts { let hosts = if args.known_hosts {
info!("Using ~/.ssh/known_hosts to build server list."); info!("Using ~/.ssh/known_hosts to build server list.");
let known_hosts = read_known_hosts(); let known_hosts = read_known_hosts();
// Build regex let mut all_hosts = Vec::new();
let re = match Regex::new(&args.expression) { for expression in args.expression.iter() {
Ok(result) => result, let re = match Regex::new(expression) {
Err(e) => { Ok(result) => result,
error!("Error parsing regex. {}", e); Err(e) => {
process::exit(1); error!("Error parsing regex. {}", e);
} process::exit(1);
}; }
// match hostnames from known_hosts to regex };
known_hosts let matched: Vec<Host> = known_hosts
.into_iter() .clone()
.filter(|r| re.is_match(&r.name.clone())) .into_iter()
.collect() .filter(|r| re.is_match(&r.name.clone()))
.collect();
all_hosts.extend(matched);
}
all_hosts
} else { } else {
info!("Using string expansion to build server list."); info!("Using string expansion to build server list.");
expand_string(&args.expression) let mut all_hosts = Vec::new();
for expression in args.expression.iter() {
all_hosts.extend(expand_string(expression));
}
all_hosts
}; };
// Dedup hosts from known_hosts file // Dedup hosts from known_hosts file
@ -234,9 +242,7 @@ fn main() {
_ => unreachable!(), _ => unreachable!(),
}) })
{ {
info!("\n");
info!("Run command on {} servers.", &config.hosts.len()); info!("Run command on {} servers.", &config.hosts.len());
info!("\n");
// Run a command on all the configured hosts. // Run a command on all the configured hosts.
// Receive the result of the command for each host and print its output. // Receive the result of the command for each host and print its output.
@ -248,8 +254,8 @@ fn main() {
.collect::<Vec<_>>()[0] .collect::<Vec<_>>()[0]
.to_string(); .to_string();
let ip = ip.parse::<IpAddr>().unwrap(); let ip = ip.parse::<IpAddr>().unwrap();
info!( println!(
"{}", "\n{}",
hosts_and_ips hosts_and_ips
.get(&ip) .get(&ip)
.unwrap_or(&"Couldn't parse IP".to_string()) .unwrap_or(&"Couldn't parse IP".to_string())
@ -265,14 +271,50 @@ fn main() {
continue; continue;
} }
}; };
if output.exit_status == 0 { let code_string = if output.exit_status == 0 {
println!("Code {}", output.exit_status); format!("{}", output.exit_status.to_string().green())
} else { } else {
error!("Code {}", output.exit_status); format!("{}", output.exit_status.to_string().red())
}; };
println!(
"{}",
format!(
"Exit code [{}] | std out/err [{}/{}] bytes",
code_string,
output.stdout.len(),
output.stderr.len()
)
.bold()
);
if !args.code { if !args.code {
println!("STDOUT:\n{}", String::from_utf8(output.stdout).unwrap()); match String::from_utf8(output.stdout) {
println!("STDERR:\n{}", String::from_utf8(output.stderr).unwrap()); Ok(stdout) => match stdout.as_str() {
"" => {}
_ => {
let prefix = if output.exit_status != 0 {
format!("{}", "".cyan())
} else {
format!("{}", "".green())
};
for line in stdout.lines() {
println!("{} {}", prefix, line);
}
}
},
Err(_) => {}
}
match String::from_utf8(output.stderr) {
Ok(stderr) => match stderr.as_str() {
"" => {}
_ => {
for line in stderr.lines() {
println!("{} {}", "".red(), line);
}
}
},
Err(_) => {}
}
} }
} }
} else { } else {