Python SSH

Hello Marios

When using Paramiko and the ssh.exec_command function, it contains what are known as three data streams. These are the input, the output, and any errors that may appear. This is known as a 3-tuple. The syntax is:

stdin, stdout, stderr = ssh.exec_command("command")

You can use any variable names you like in place of stdin, stdout, and stderr.

All three of these streams are returned whenever the ssh.exec_command function is executed and they contain the following information:

  • stdin - the input stream. This contains the actual commands that were sent
  • stdout - the output stream. This contains the output that the CLI returns in response to the command
  • stderr - any errors that may have appeared are stored herre.

These streams act as standard Python object files and can be manipulated as such. That’s why in the lesson, you see a command such as output = ssh_stdout.readlines().

Take a look at this information from Paramiko, and in particular, the explanation for the exec_command.
https://docs.paramiko.org/en/stable/api/client.html

I hope this has been helpful!

Laz

1 Like