import os
import sys
import shutil
import platform
import traceback
from optparse import OptionParser
import subprocess
import commands
import paramiko
import time
reload(sys)
sys.setdefaultencoding('utf8')
import re
def connect():
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
try:
ssh.connect(hostname = hostname,username=username,password=password,allow_agent=True,timeout = 5)
return ssh
except:
print "********************连接失败*********************"
return None
def main():
# 1.连接ssh
paramiko.util.log_to_file('paramiko.log')
ssh = connect()
stdin, stdout, stderr = ssh.exec_command("ls /var/containers/Bundle/Application")
applicationList = stdout.readlines()
if __name__ == '__main__':
hostname = '192.168.18.146'
username = 'root'
password = 'alpine'
main()