This commit is contained in:
2020-05-04 22:13:47 +08:00
parent 8d21962637
commit fd83169ba4
3 changed files with 1285 additions and 2 deletions

1207
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -10,4 +10,6 @@ edition = "2018"
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0" serde_json = "1.0"
argparse = "0.2.2" argparse = "0.2.2"
rust_util = "0.2.4"
dingtalk = "1.3.2"

View File

@@ -1,3 +1,77 @@
fn main() { use std::process::Command;
println!("Hello, world!"); use serde::{ Deserialize, Serialize, };
use rust_util::util_msg::{ print_info, print_error, };
#[derive(Debug, Clone, Serialize, Deserialize)]
struct KeepRunningConfig {
notify_token: String,
items: Vec<KeepRunningConfigItem>,
} }
#[derive(Debug, Clone, Serialize, Deserialize)]
struct KeepRunningConfigItem {
grep_tokens: Vec<String>,
title: String,
}
fn main() {
print_info("Start run: ps aux");
let output_str = match ps_aux() {
Some(output_str) => output_str, None => return,
};
let lines = read_str_to_lines(&output_str);
// println!("{}", output_str);
// for ln in &lines {
// println!(">>>>>>> {}", ln);
// }
println!("{:?}", lines.iter().filter(|ln| ln.contains("java") && ln.contains("aaa")).collect::<Vec<_>>());
println!("{}", lines.len());
}
fn ps_aux() -> Option<String> {
let mut cmd = Command::new("ps");
cmd.arg("aux");
let output = match cmd.output() {
Ok(output) => output, Err(err) => {
print_error(&format!("Run ps error: {}", err));
return None;
},
};
match String::from_utf8(output.stdout) {
Ok(output_str) => Some(output_str), Err(err) => {
print_error(&format!("Get ps output as utf8 error: {}", err));
return None;
},
}
}
fn read_str_to_lines(s: &str) -> Vec<String> {
let mut r = vec![];
let mut line = String::new();
let mut cs = s.chars();
while let Some(c) = cs.next() {
if c == '\n' || c == '\r' {
r.push(line.clone());
line.clear();
if c == '\r' {
if let Some(nc) = cs.next() {
if nc == '\n' {
// IGNORE
} else if nc == '\r' {
r.push("".to_owned());
} else {
line.push(nc);
}
}
}
} else {
line.push(c);
}
}
if !line.is_empty() {
r.push(line);
}
r
}