The code that I use is the following:
def ssh(host, cmd, user, password, timeout=30, bg_run=False):                                                                                                 
  """SSH'es to a host using the supplied credentials and executes a command.                                                                                                 
  Throws an exception if the command doesn't return 0.                                                                                                                       
  bgrun: run command in the background"""                                                                                                                                    
  fname = tempfile.mktemp()                                                                                                                                                  
  fout = open(fname, 'w')                                                                                                                                                    
  options = '-q -oStrictHostKeyChecking=no -oUserKnownHostsFile=/dev/null -oPubkeyAuthentication=no'                                                                         
  if bg_run:                                                                                                                                                         
    options += ' -f'                                                                                                                                                       
  ssh_cmd = 'ssh %s@%s %s "%s"' % (user, host, options, cmd)                                                                                                                 
  child = pexpect.spawn(ssh_cmd, timeout=timeout)                                                                                                                            
  child.expect(['password: '])                                                                                                                                                                                                                                                                                               
  child.sendline(password)                                                                                                                                                   
  child.logfile = fout                                                                                                                                                       
  child.expect(pexpect.EOF)                                                                                                                                                  
  child.close()                                                                                                                                                              
  fout.close()                                                                                                                                                               
  fin = open(fname, 'r')                                                                                                                                                     
  stdout = fin.read()                                                                                                                                                        
  fin.close()                                                                                                                                                                
  if 0 != child.exitstatus:                                                                                                                                                  
    raise Exception(stdout)                                                                                                                                                
  return stdout
I have noticed that the file on the remote is being created, but it is not populated. The cmd arg I use is something like this:
cmd = 'cd toTheLocation; /bin/bash ack "Pattern" file.txt > output.csv'
I have taken that function from this question (I already tried paramiko and the spur wrapper and I have the same problem): Sending a password over SSH or SCP with subprocess.Popen
Thanks for the help
