Skip to content
Advertisement

How to skip lines when printing output from Paramiko SSH

So I built a program that prints out the login logs of my ubuntu server using tail -f. The program uses Paramiko to connect via ssh and runs the command to tail the logs. The program works but it prints out the motd from the server which is unnecessary.

I’ve tried splicing using itertools. Tried using next(). Still doesn’t work.

Here’s my code:

JavaScript

Advertisement

Answer

You get MOTD because you are opening an interactive shell session. I do not think you need that, quite on the contrary.

Use SSHClient.exec_command instead:

JavaScript

Related questions:


Obligatory warning: Do not use AutoAddPolicy – You are losing a protection against MITM attacks by doing so. For a correct solution, see Paramiko “Unknown Server”.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement