Tuesday, July 25, 2017

Python + Paramiko = SSH unhappiness :(

Been reading the book, watching random YouTube videos on Python.. reading articles and blog posts. Figure one of the best ways to learn something is by doing, so I thought and thought and what's one of the most used parts of a script?

Connecting to a remote machine!

So I went with Paramiko as it seems to be the defacto SSHing inside Python .. thing.  Following examples is still tricky.  I created a new EC2 instance for this.. churned out a short script or snippet as I like to call it.  A paramiko_snippet on using the SSH client but am having issues sending remote commands.

I can connect, and invoke_shell() returns an active channel so I'm good there.

But when sending commands, 'channel.send('command')' returns nothing but a number.. in this case a 2.. next time I ran it gave me a 3.

Maybe it's some Python 2 versus 3 issue.  It's not clear yet, but my Google-Fu is strong and I will figure it out.

channel.send('ls')
2
channel.send('ls\n')
3

No comments:

Post a Comment