Implement single host as argument

This commit is contained in:
Lord Of Nougate 2022-08-25 18:56:26 +02:00
parent 1531dc3b28
commit cdc4dfa13b

View File

@ -1,6 +1,7 @@
#!/bin/python #!/bin/python
import os import os
import sys
import subprocess import subprocess
ssh_config = os.path.expanduser('~') + "/.ssh/config" ssh_config = os.path.expanduser('~') + "/.ssh/config"
@ -10,22 +11,30 @@ with open(ssh_config) as file:
#ping -c 1 -w 1 #ping -c 1 -w 1
for l in file_content: if sys.argv[1] != None:
if "host " in l: ssh_host = sys.argv[1]
l_index = file_content.index(l) command = f"infocmp | ssh {ssh_host} 'tic -x /dev/stdin'"
index = l_index + 1 return_value = subprocess.call(command, shell=True, stdout=open(os.devnull, "w"), stderr=subprocess.STDOUT)
host_ip = file_content[index].split()[1] if return_value == 1:
print(f"Could not send terminfo to {ssh_host}")
return_value = subprocess.call(["ping", "-c1", "-w1", host_ip], stdout=open(os.devnull, "w"), stderr=subprocess.STDOUT) else:
for l in file_content:
if "host " in l:
l_index = file_content.index(l)
index = l_index + 1
host_ip = file_content[index].split()[1]
if return_value == 0: return_value = subprocess.call(["ping", "-c1", "-w1", host_ip], stdout=open(os.devnull, "w"), stderr=subprocess.STDOUT)
ssh_host = l.split()[1]
print(f"Host {ssh_host} ({host_ip}) is up. Sending terminfo..") if return_value == 0:
ssh_host = l.split()[1]
command = f"infocmp | ssh {ssh_host} 'tic -x /dev/stdin'" print(f"Host {ssh_host} ({host_ip}) is up. Sending terminfo..")
return_value = subprocess.call(command, shell=True, stdout=open(os.devnull, "w"), stderr=subprocess.STDOUT) command = f"infocmp | ssh {ssh_host} 'tic -x /dev/stdin'"
if return_value == 1: return_value = subprocess.call(command, shell=True, stdout=open(os.devnull, "w"), stderr=subprocess.STDOUT)
print(f"Could not send terminfo to {ssh_host}")
if return_value == 1:
print(f"Could not send terminfo to {ssh_host}")