Я создал скрипт на python, который инициируется как сеанс SSH (между окнами и Linux) и позволяет выполнять команды.
Теперь мне нужно соединить скрипт Python с TCL.
Мне нужно вызвать этот скрипт с некоторыми аргументами, используя TCL, и получить ответ на TCL консоли Python.
это мой скрипт на Python:
импорт потоков, парамико
из парамико импортный клиент
время импорта
класс ssh:
клиент = нет
оболочка = нет
def __init__(self, address, username):
print("Connecting to server.")
cert = paramiko.RSAKey.from_private_key_file("QA-SIP-Evgenyz.pem")
self.client = client.SSHClient()
self.client.set_missing_host_key_policy(client.AutoAddPolicy())
self.client.connect(address, username=username, pkey=cert)
self.transport = paramiko.Transport((address, 22))
self.transport.connect(username=username, pkey=cert)
thread = threading.Thread(target=self.process)
thread.daemon = True
thread.start()
print("Connected")
def closeConnection(self):
if self.client is not None:
self.client.close()
self.transport.close()
def openShell(self):
self.shell = self.client.invoke_shell()
def sendShell(self, command):
if self.shell:
#print("trying to run command " + command)
self.shell.send(command + "\r")
time.sleep(0.6)
#self.shell.send("\r")
else:
print("Shell not opened.")
def process(self):
global connection
while True:
# Print data when available
if self.shell is not None and self.shell.recv_ready():
alldata = self.shell.recv(1024)
while self.shell.recv_ready():
alldata += self.shell.recv(1024)
strdata = str(alldata, "utf8")
strdata.replace('\r', '')
print(strdata, end = "")
if strdata.endswith("$ "):
print("\n$ ", end = "")
IP = 1.1.1.1
user = ubuntu
connection = ssh("IP", "user")
connection.openShell()
while True:
#Just to test the connection
connection.sendShell("ls -l")
Теперь мне нужно найти способ вызвать этот класс Python через TCL с аргументами.
Я не уверен, как написать класс Python, чтобы иметь возможность получать ards из других мест.
А также, как работает «возврат», как показать консоль?