rsblocks/src/disk.rs

20 lines
534 B
Rust
Raw Normal View History

2020-12-21 11:29:45 +01:00
use std::process::Command;
pub fn disk_free() -> String {
let cmd = Command::new("sh")
.arg("-c")
.args(&["df -h"])
.output()
.unwrap();
let output = String::from_utf8_lossy(&cmd.stdout);
let mut disk_used = String::new();
for line in output.lines() {
if line.ends_with('/') {
let splited = line.split_whitespace().collect::<Vec<&str>>();
disk_used = splited[2].to_string();
break;
}
}
format!("{}", disk_used)
}