1 Commits
1.1.0 ... 1.0.9

Author SHA1 Message Date
1eb9c5c17d Added multiple -e 2023-09-07 17:40:37 +03:00
3 changed files with 26 additions and 17 deletions

2
Cargo.lock generated
View File

@ -1066,7 +1066,7 @@ checksum = "436b050e76ed2903236f032a59761c1eb99e1b0aead2c257922771dab1fc8c78"
[[package]] [[package]]
name = "rexec" name = "rexec"
version = "1.0.8" 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.8" 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

@ -34,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,
@ -156,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