M README.md => README.md +9 -7
@@ 25,18 25,20 @@ USAGE:
rice_stats [FLAGS] [OPTIONS]
FLAGS:
- -a, --apt This flag will cause the program to run `apt update -y && apt upgrade` updating the apt repository
- but NOT the packages and then output the parsed number of available updates REQUIRES SUID bit to be
- set on this binary via: sudo chown <this binary> && sudo chmod u+s <this binary> or alternatively
- this binary can be run as an elevated user
- -h, --help Prints help information
- -u, --usage Return the current network usage for the primary interface
- -V, --version Prints version information
+ -a, --apt This flag will cause the program to run `apt update -y && apt upgrade` updating the apt
+ repository but NOT the packages and then output the parsed number of available updates REQUIRES
+ SUID bit to be set on this binary via: sudo chown <this binary> && sudo chmod u+s <this binary>
+ or alternatively this binary can be run as an elevated user
+ -h, --help Prints help information
+ -s, --sys-uptime Return the system uptime in days
+ -u, --usage Return the current network usage for the primary interface
+ -V, --version Prints version information
OPTIONS:
-i, --interface <interface> Override the interface that is used for several commands. If this is not provided an
attempt will be made to find the primary interface based on the presence of an ip and
then traffic rate
+
```
## Usage
M src/main.rs => src/main.rs +1 -1
@@ 53,7 53,7 @@ fn main() {
if args.sys_uptime == true {
if let Err(e) = get_uptime(&mut output_line){
- eprintln!("Error received attempting show_updates: {}",e);
+ eprintln!("Error received attempting to get uptime: {}",e);
}
}
print!("{}",output_line);
A src/oneliners.rs => src/oneliners.rs +22 -0
@@ 0,0 1,22 @@
+pub use std::{fmt,error::Error,process::Command};
+use rice_stats::{run_command};
+
+pub fn get_uptime (output_line: &mut String) -> Result<(),Box<dyn Error>> {
+ let mut command_to_parse = String::new();
+ run_command("uptime", &mut command_to_parse)?;
+
+ let pattern = regex::Regex::new("\\d+? days")?;
+ let p_match = pattern.captures(&command_to_parse);
+ match p_match {
+ Some(v) => {
+ output_line.push_str("Uptime: ");
+ output_line.push_str(&v[0]);
+ output_line.push_str(" ");
+ return Ok(());
+ },
+ None => {
+ return Ok(());
+ }
+ }
+}
+