1

I just started learning paramiko and am trying to inject simple commands into the server via SSH. The first command works as it should and returns a response, but I don't get any response from the others. After the first two commands, I need to send "Y" for confirmation and then press "enter" 3 times. The code shows that I tried to set large time delays, but this did not help. Please point out my mistakes

import time
import paramiko

host = 'host'
user = 'root'
secret = 'secret'
port = 22
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(hostname=host, username=user, password=secret, port=port)

stdin, stdout, stderr = client.exec_command("apt update\n")
time.sleep(5)
data = stdout.read() + stderr.read()
print(data)


stdin, stdout, stderr = client.exec_command('apt upgrade\n')
time.sleep(200)

data = stdout.read() + stderr.read()
print(data)

stdin, stdout, stderr = client.exec_command('Y\n')
time.sleep(100)
data = stdout.read() + stderr.read()
print(data)

stdin, stdout, stderr = client.exec_command('\n')
time.sleep(100)
data = stdout.read() + stderr.read()
print(data)

stdin, stdout, stderr = client.exec_command('\n')
time.sleep(100)
data = stdout.read() + stderr.read()
print(data)

stdin, stdout, stderr = client.exec_command('\n')
time.sleep(100)
data = stdout.read() + stderr.read()
print(data)

client.close()

0 Answers0