I'm pretty new to Python, however I've been trying to write a script that first connects to server via SSH, then issues and command to read the contents of a file. <-- this works
My issue now is that I really don't want all of the contents of the file. I'd like to pass the output from the SSH command and then print out only lines matching particular search terms. I'm having a lot of trouble getting this to work and I'm sure this can't be that complicated.
All the examples I've found online pretty much involve a filename.txt to start with. However in my case I'm trying to read a file through SSH and then only display what I want. Hoping someone can provide me some sort of example on how I can achieve this.
I've included my code below with only the reading of the file part since nothing I was doing past that would work.
- Code: Select all
ssh = paramiko.SSHClient()
ssh.connect('HOSTIP', username='myusername', password='mypassword')
stdin, stdout, stderr = ssh.exec_command("cat /path/to/my/text/mytext.txt")
data = stdout.read()
Hope someone can help!