As I see if my script runs correctly

0

This is my script That connects by ssh to a mikrotik and executes a command I just want you to go telling me all the steps as it is fulfilled.

import paramiko

client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect('x.x.x.x', username='++', password='+++++++')

stdin, stdout, stderr = client.exec_command('/ip dhcp-client release [find interface=wlan5]')
    
asked by Angel Luis Robles Preciado 03.01.2019 в 19:34
source

2 answers

0

I can think of something like this.

import paramiko

client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect('x.x.x.x', username='++', password='+++++++')

stdin, stdout, stderr = client.exec_command('/ip dhcp-client release [find interface=wlan5]')

while True:
    data = stdout.channel.recv(4096)
    if data:
        text = data.decode()
        print(text)
    else:
        break

With that you can show the stdout while it is running and when there is nothing to read, close the cycle to continue with the rest of the flow. I can not say it's a perfect solution or even a very good one, but it can help you.

    
answered by 05.01.2019 / 03:20
source
0

As Saelyth says, it should be enough to make one:

print(stdout.read())

However, this will show the result of what you did, at one time, and not in real time, which is what I understand you need when you say "as it is fulfilled".

    
answered by 04.01.2019 в 21:27