diff --git a/ssh_with_sub/main.py b/ssh_with_sub/main.py index e09aec7..9a66c5f 100755 --- a/ssh_with_sub/main.py +++ b/ssh_with_sub/main.py @@ -26,6 +26,15 @@ def ssh_connection(con_server= str,con_user = str,bash_script = """ls"""): stderr=subprocess.PIPE, ).communicate() +def ssh_connection_tt(con_server= str,con_user = str,bash_script = """ls"""): + return subprocess.Popen( + "echo '{cmd};exit'|ssh {host} -tt sudo su - {user} ".format(user=con_user, host=con_server, cmd=bash_script), + shell=True, + universal_newlines=True, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + ).communicate() + def ssh_check(con_server = str, check_port = 22): response = os.system("ping -c 1 " + con_server + '>& /dev/null') @@ -44,6 +53,7 @@ GREP_PACK="atlas_ibtools" echo "test" bash --version """ + run_oneline_bash="""ll; echo 'test'""" for count in range(0,len(read_csv(server_csv)['server'])): servername = read_csv(server_csv)['server'][count] con_username = read_csv(server_csv)['user'][count] @@ -51,6 +61,10 @@ bash --version print(servername, "verbindng wird geprüft...",sep=' ') if ssh_check(con_server=servername) is True: print(servername, "erreichbar...", sep=' ') + + for show_output in list(ssh_connection_tt(con_server=servername, con_user=con_username, bash_script=run_oneline_bash)): + print(show_output.rstrip()) + for show_output in list(ssh_connection(con_server=servername, con_user=con_username, bash_script=run_script_bash)): print(show_output.rstrip()) else: