use std::io::prelude::*; use std::net::TcpStream; use ssh2::Session; use emojis_rs::*; const USER: &str = "aaronh"; const EDI: &str = "100.94.173.5:22"; fn main() { // Connect to the local SSH server let tcp = TcpStream::connect(EDI).unwrap(); let mut sess = Session::new().unwrap(); sess.set_tcp_stream(tcp); sess.handshake().unwrap(); // Try to authenticate with the first identity in the agent. sess.userauth_agent(USER).unwrap(); if sess.authenticated() { println!("Authentication successful! {EMOJI_CHECK}"); } else { println!("Authentication failed! {EMOJI_CROSS}"); } println!("-------------------------"); let mut gollum_check = sess.channel_session().unwrap(); gollum_check.exec("systemctl is-active gollum").unwrap(); let mut s = String::new(); gollum_check.read_to_string(&mut s).unwrap(); gollum_check.wait_close().unwrap(); let exit_code = gollum_check.exit_status().unwrap(); if exit_code == 0 { println!("Gollum service is active {EMOJI_CHECK}"); } else { println!("Gollum service is inactive {EMOJI_CROSS}(exit code: {})", exit_code); } let mut wastebin_check = sess.channel_session().unwrap(); wastebin_check.exec("systemctl is-active wastebin").unwrap(); let mut s = String::new(); wastebin_check.read_to_string(&mut s).unwrap(); wastebin_check.wait_close().unwrap(); let exit_code = wastebin_check.exit_status().unwrap(); if exit_code == 0 { println!("Wastebin service is active {EMOJI_CHECK}"); } else { println!("Wastebin service is inactive {EMOJI_CROSS}(exit code: {})", exit_code); } }