commit message from python script
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
#!/usr/bin/env python3.10
|
#!/usr/bin/env python3.10
|
||||||
from subprocess import Popen, PIPE
|
|
||||||
from csv import DictReader
|
from csv import DictReader
|
||||||
import os, socket
|
import os, socket, subprocess
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -18,14 +17,15 @@ def read_csv(csv_file = str):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def ssh_connection(con_server = str, bash_script = """ls -lisaR /home; apt list --installed"""):
|
def ssh_connection(con_server= str,con_user = str,bash_script = """ls"""):
|
||||||
with Popen(['ssh', '-T', str(con_server)],
|
return subprocess.Popen(
|
||||||
stdin=PIPE, stdout=PIPE, stderr=PIPE,
|
"ssh -T {user}@{host} '{cmd}'".format(user=con_user, host=con_server, cmd=bash_script),
|
||||||
universal_newlines=True) as p:
|
shell=True,
|
||||||
output, error = p.communicate(bash_script)
|
universal_newlines=True,
|
||||||
print(output)
|
stdout=subprocess.PIPE,
|
||||||
print(error)
|
stderr=subprocess.PIPE,
|
||||||
print(p.returncode)
|
).communicate()
|
||||||
|
|
||||||
|
|
||||||
def ssh_check(con_server = str, check_port = 22):
|
def ssh_check(con_server = str, check_port = 22):
|
||||||
response = os.system("ping -c 1 " + con_server + '>& /dev/null')
|
response = os.system("ping -c 1 " + con_server + '>& /dev/null')
|
||||||
@@ -39,7 +39,11 @@ def ssh_check(con_server = str, check_port = 22):
|
|||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
script_folder = os.path.dirname(os.path.realpath(__file__))
|
script_folder = os.path.dirname(os.path.realpath(__file__))
|
||||||
server_csv = script_folder + os.sep + "test.csv"
|
server_csv = script_folder + os.sep + "test.csv"
|
||||||
|
run_script_bash = """
|
||||||
|
GREP_PACK="atlas_ibtools"
|
||||||
|
echo "test"
|
||||||
|
bash --version
|
||||||
|
"""
|
||||||
for count in range(0,len(read_csv(server_csv)['server'])):
|
for count in range(0,len(read_csv(server_csv)['server'])):
|
||||||
servername = read_csv(server_csv)['server'][count]
|
servername = read_csv(server_csv)['server'][count]
|
||||||
con_username = read_csv(server_csv)['user'][count]
|
con_username = read_csv(server_csv)['user'][count]
|
||||||
@@ -47,7 +51,8 @@ if __name__ == "__main__":
|
|||||||
print(servername, "verbindng wird geprüft...",sep=' ')
|
print(servername, "verbindng wird geprüft...",sep=' ')
|
||||||
if ssh_check(con_server=servername) is True:
|
if ssh_check(con_server=servername) is True:
|
||||||
print(servername, "erreichbar...", sep=' ')
|
print(servername, "erreichbar...", sep=' ')
|
||||||
ssh_connection(con_server=user_server_con)
|
for show_output in list(ssh_connection(con_server=servername, con_user=con_username, bash_script=run_script_bash)):
|
||||||
|
print(show_output.rstrip())
|
||||||
else:
|
else:
|
||||||
print(servername, "nicht erreichbar oder kein ssh!!", sep=' ')
|
print(servername, "nicht erreichbar oder kein ssh!!", sep=' ')
|
||||||
#if ssh_check(con_server=servername) is True:
|
#if ssh_check(con_server=servername) is True:
|
||||||
|
|||||||
Reference in New Issue
Block a user