mirror of
https://github.com/house-of-vanity/rexec.git
synced 2025-07-08 09:14:08 +00:00
Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
3cf1e79883 | |||
0d95364e50 | |||
48635fc091 | |||
5ed62d9323 | |||
c635ed0dd0 |
2
.gitignore
vendored
2
.gitignore
vendored
@ -1 +1,3 @@
|
|||||||
target
|
target
|
||||||
|
pkg
|
||||||
|
*zst
|
||||||
|
@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|||||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
|
|
||||||
|
## [1.0.4] - 2023-08-14
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- Expansion host strings.
|
||||||
|
|
||||||
## [1.0.1] - 2023-06-20
|
## [1.0.1] - 2023-06-20
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
3
Cargo.lock
generated
3
Cargo.lock
generated
@ -1043,7 +1043,7 @@ checksum = "436b050e76ed2903236f032a59761c1eb99e1b0aead2c257922771dab1fc8c78"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rexec"
|
name = "rexec"
|
||||||
version = "1.0.3"
|
version = "1.0.4"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"brace-expand",
|
"brace-expand",
|
||||||
"clap 4.3.4",
|
"clap 4.3.4",
|
||||||
@ -1056,7 +1056,6 @@ dependencies = [
|
|||||||
"log",
|
"log",
|
||||||
"massh",
|
"massh",
|
||||||
"regex",
|
"regex",
|
||||||
"tokio",
|
|
||||||
"whoami",
|
"whoami",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "rexec"
|
name = "rexec"
|
||||||
version = "1.0.3"
|
version = "1.0.4"
|
||||||
|
readme = "https://github.com/house-of-vanity/rexec#readme"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
description = "Parallel SSH executor"
|
description = "Parallel SSH executor"
|
||||||
repository = "https://github.com/house-of-vanity/rexec"
|
repository = "https://github.com/house-of-vanity/rexec"
|
||||||
@ -12,7 +13,6 @@ authors = ["AB <gh@hexor.ru>"]
|
|||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
tokio = { version = "1", features = ["full"] }
|
|
||||||
dns-lookup = "2.0.2"
|
dns-lookup = "2.0.2"
|
||||||
log = "0.4.0"
|
log = "0.4.0"
|
||||||
env_logger = "0.10.0"
|
env_logger = "0.10.0"
|
||||||
|
25
PKGBUILD
Normal file
25
PKGBUILD
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
# Maintainer: AB <gh@hexor.ru>
|
||||||
|
pkgname=rexec
|
||||||
|
pkgver=1.0.1.r9.g0d95364
|
||||||
|
pkgrel=1
|
||||||
|
pkgdesc="Parallel SSH executor"
|
||||||
|
url="https://github.com/house-of-vanity/rexec"
|
||||||
|
license=("WTFPL")
|
||||||
|
arch=("x86_64")
|
||||||
|
makedepends=("cargo")
|
||||||
|
|
||||||
|
pkgver() {
|
||||||
|
(git describe --long --tags || echo "$pkgver") | sed 's/^v//;s/\([^-]*-g\)/r\1/;s/-/./g'
|
||||||
|
}
|
||||||
|
|
||||||
|
build() {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
package() {
|
||||||
|
cd ..
|
||||||
|
usrdir="$pkgdir/usr"
|
||||||
|
mkdir -p $usrdir
|
||||||
|
cargo install --no-track --path . --root "$usrdir"
|
||||||
|
}
|
||||||
|
|
31
src/main.rs
31
src/main.rs
@ -24,13 +24,13 @@ struct Args {
|
|||||||
#[arg(short, long, default_value_t = whoami::username())]
|
#[arg(short, long, default_value_t = whoami::username())]
|
||||||
username: String,
|
username: String,
|
||||||
|
|
||||||
#[arg(short, long, help = "Use known_hosts to build servers list")]
|
#[arg(short, long, help = "Use known_hosts to build servers list instead of string expansion.")]
|
||||||
known_hosts: bool,
|
known_hosts: bool,
|
||||||
|
|
||||||
#[arg(
|
#[arg(
|
||||||
short,
|
short,
|
||||||
long,
|
long,
|
||||||
help = "Expression to build server list. List and range expansion available. 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: String,
|
||||||
|
|
||||||
@ -91,8 +91,14 @@ fn expand_string(s: &str) -> Vec<Host> {
|
|||||||
|
|
||||||
while let Some(r) = result.iter().find(|s| s.contains('[')) {
|
while let Some(r) = result.iter().find(|s| s.contains('[')) {
|
||||||
let r = r.clone();
|
let r = r.clone();
|
||||||
let start = r.find('[').unwrap();
|
let start = r.find(']').unwrap();
|
||||||
let end = r.find(']').unwrap();
|
let end = match r.find(']') {
|
||||||
|
None => {
|
||||||
|
error!("Error parsing host expression. Wrong range expansion '[a:b]'");
|
||||||
|
process::exit(1);
|
||||||
|
}
|
||||||
|
Some(s) => s
|
||||||
|
};
|
||||||
let colon = r.find(':').unwrap();
|
let colon = r.find(':').unwrap();
|
||||||
let low = r[start+1..colon].parse::<i32>().unwrap();
|
let low = r[start+1..colon].parse::<i32>().unwrap();
|
||||||
let high = r[colon+1..end].parse::<i32>().unwrap();
|
let high = r[colon+1..end].parse::<i32>().unwrap();
|
||||||
@ -106,7 +112,13 @@ fn expand_string(s: &str) -> Vec<Host> {
|
|||||||
while let Some(r) = result.iter().find(|s| s.contains('{')) {
|
while let Some(r) = result.iter().find(|s| s.contains('{')) {
|
||||||
let r = r.clone();
|
let r = r.clone();
|
||||||
let start = r.find('{').unwrap();
|
let start = r.find('{').unwrap();
|
||||||
let end = r.find('}').unwrap();
|
let end = match r.find('}') {
|
||||||
|
None => {
|
||||||
|
error!("Error parsing host expression. Wrong range expansion '{{one,two}}'");
|
||||||
|
process::exit(1);
|
||||||
|
}
|
||||||
|
Some(s) => s
|
||||||
|
};
|
||||||
let list = &r[start+1..end];
|
let list = &r[start+1..end];
|
||||||
result.retain(|s| s != &r);
|
result.retain(|s| s != &r);
|
||||||
for val in expand_list(list) {
|
for val in expand_list(list) {
|
||||||
@ -124,8 +136,8 @@ fn expand_string(s: &str) -> Vec<Host> {
|
|||||||
hosts
|
hosts
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::main]
|
|
||||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
fn main() {
|
||||||
env_logger::Builder::from_env(Env::default().default_filter_or("info"))
|
env_logger::Builder::from_env(Env::default().default_filter_or("info"))
|
||||||
.format_timestamp(None)
|
.format_timestamp(None)
|
||||||
.format_target(false)
|
.format_target(false)
|
||||||
@ -159,6 +171,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
// Build MasshHostConfig hostnames list
|
// Build MasshHostConfig hostnames list
|
||||||
let mut massh_hosts: Vec<MasshHostConfig> = vec![];
|
let mut massh_hosts: Vec<MasshHostConfig> = vec![];
|
||||||
let mut hosts_and_ips: HashMap<IpAddr, String> = HashMap::new();
|
let mut hosts_and_ips: HashMap<IpAddr, String> = HashMap::new();
|
||||||
|
if args.parallel != 100 {
|
||||||
|
warn!("Parallelism: {} thread{}", &args.parallel, {if args.parallel != 1 {"s."} else {"."}});
|
||||||
|
}
|
||||||
|
|
||||||
info!("Matched hosts:");
|
info!("Matched hosts:");
|
||||||
for host in matched_hosts.iter() {
|
for host in matched_hosts.iter() {
|
||||||
let ip = match lookup_host(&host.name) {
|
let ip = match lookup_host(&host.name) {
|
||||||
@ -242,5 +258,4 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
} else {
|
} else {
|
||||||
warn!("Stopped");
|
warn!("Stopped");
|
||||||
}
|
}
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user