added more
This commit is contained in:
39
ssh_with_sub/main.py
Normal file
39
ssh_with_sub/main.py
Normal file
@@ -0,0 +1,39 @@
|
||||
#!/usr/bin/env python3.10
|
||||
from subprocess import Popen, PIPE
|
||||
from csv import DictReader
|
||||
|
||||
def read_csv(csv_file = str):
|
||||
with open(csv_file, newline='') as csv:
|
||||
read_server = DictReader(csv)
|
||||
server_liste, user_liste = [] , []
|
||||
for row in read_server:
|
||||
user_liste.append(row['user'])
|
||||
server_liste.append(row['\ufeffserver'])
|
||||
|
||||
return {
|
||||
'server' : server_liste,
|
||||
'user' : user_liste
|
||||
}
|
||||
|
||||
|
||||
def ssh_connection(con_server = str):
|
||||
with Popen(['ssh', '-T', con_server],
|
||||
stdin=PIPE, stdout=PIPE, stderr=PIPE,
|
||||
universal_newlines=True) as p:
|
||||
output, error = p.communicate("""
|
||||
ls -lisaR /home
|
||||
apt list --installed
|
||||
""")
|
||||
print(output)
|
||||
print(error)
|
||||
print(p.returncode)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
for count in range(0,len(read_csv("test.csv")['server'])):
|
||||
print("Server:", read_csv("test.csv")['server'][count], "User:", read_csv("test.csv")['user'][count], sep=" ")
|
||||
ssh_connection(con_server=read_csv("test.csv")['server'][count])
|
||||
|
||||
6
ssh_with_sub/test.csv
Normal file
6
ssh_with_sub/test.csv
Normal file
@@ -0,0 +1,6 @@
|
||||
server,user, command
|
||||
ubuntu,jonnybravo1,
|
||||
debian,jonnybravo2,
|
||||
3server,beuntzer2,
|
||||
klana,beuntzer23,
|
||||
bababa,dkdkd,
|
||||
|
Reference in New Issue
Block a user