From 1531dc3b289811c9294d6b4e69462c9fb782afac Mon Sep 17 00:00:00 2001 From: sevi-kun Date: Sat, 7 May 2022 13:46:48 +0200 Subject: [PATCH] Finished ssh_terminfo --- ssh_terminfo.py | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/ssh_terminfo.py b/ssh_terminfo.py index 0d0d7d4..2073890 100755 --- a/ssh_terminfo.py +++ b/ssh_terminfo.py @@ -1,19 +1,31 @@ #!/bin/python import os +import subprocess -path = os.path.expanduser('~') + "/.ssh/config" +ssh_config = os.path.expanduser('~') + "/.ssh/config" -f = open(path,"r") -lines = f.readlines() +with open(ssh_config) as file: + file_content = list(file) #ping -c 1 -w 1 -print(lines.count()) - -for l in lines: +for l in file_content: if "host " in l: - ssh_host = l.split()[1] - command = f"infocmp | ssh {ssh_host} 'tic -x /dev/stdin'" - print("Sending terminfo to: " + ssh_host) - print("Command: " + command) + l_index = file_content.index(l) + index = l_index + 1 + host_ip = file_content[index].split()[1] + + return_value = subprocess.call(["ping", "-c1", "-w1", host_ip], stdout=open(os.devnull, "w"), stderr=subprocess.STDOUT) + + if return_value == 0: + ssh_host = l.split()[1] + + print(f"Host {ssh_host} ({host_ip}) is up. Sending terminfo..") + + command = f"infocmp | ssh {ssh_host} 'tic -x /dev/stdin'" + + return_value = subprocess.call(command, shell=True, stdout=open(os.devnull, "w"), stderr=subprocess.STDOUT) + + if return_value == 1: + print(f"Could not send terminfo to {ssh_host}")