I'm trying to write a function where it would ssh into a remote host and for every file in a directory, process it.
For example, my current function for the for loop is:
import fnmatch, os
def process_logfiles_in_remote_directory(remotedir):
for filename in os.listdir(remotedir):
if fnmatch.fnmatch(filename, '*.log'):
filename = os.path.join(remotedir, filename)
## Do something here...
How do I wrap the above function in a ssh connection, something in the line of this:
ssh_client = paramiko.SSHClient()
ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh_client.connect("www.remotehost.com", username="admin", password="testing")
stdin, stdout, stderr = ssh_client.exec_command(process_logfiles_in_remote_directory('/tmp'))
ssh_client.close()