import sys,os sys.stderr = open('/dev/null') import paramiko sys.stderr = sys.__stderr__
os.system("echo \'s3\' >> myfile.txt ") #debug first in ssh2 def ssh2_connect(host, user, pswd, port=22): try: ssh = paramiko.SSHClient() ssh.load_system_host_keys() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.connect(host, port, user, pswd) return ssh except Exception, e: return str(e) + "Error. Failed to connect. Wrong IP/Username/Password" def ssh2_exec(ssh, cmd, sudo=False): result = [] try: channel = ssh.get_transport().open_session() if sudo: channel.get_pty() except: return result stdin = channel.makefile('wb') stdout = channel.makefile('rb') channel.exec_command(cmd) exit_status = channel.recv_exit_status() if exit_status == 0: for line in stdout: result.append(line) channel.close() return result def ssh2_close(ssh): ssh.close() return def ssh2_copyToFile(ssh, local_file, remote_file): sftp = paramiko.SFTPClient.from_transport(ssh.get_transport()) sftp.put(local_file, remote_file) return -- http://mail.python.org/mailman/listinfo/python-list