#!/usr/bin/env python import os, sys # first let's copy the script to be run (can be python, shell, perl, whatever =) #stdin, stdout, stderr = os.popen3("scp -p myScript.py remotehost:") # close the previous file descriptors: #stdin.close() #stdout.close() #stderr.close() # and now ssh into the remotehost and launch the script we just uploaded to it... stdin, stdout, stderr = os.popen3("ssh study1 -ladelux") # pass password stdin.write("""adelux""") print stdout.read() # chmod and execute the script... #stdin.write("""chmod 700 myScript.py\n""") #stdin.write("""./myScript.py\n""") # then close the ssh connection stdin.write("""exit\n""") # and close the file descriptors: stdin.close() stdout.close() stderr.close()