def sql_init(ip,username,password,cmd):
try:
client = paramiko.SSHClient()
# Default accept unknown keys
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
# Connect
client.connect(ip, port=22, username=username, password=password,timeout="20s")
# Execute shell remotely
stdin, stdout, stderr = client.exec_command(cmd)
stdout.read()
print stdout
client.close()
#sftp = client.open_sftp()
# Make a dir
#sftp.mkdir('/home/testssh')
# Down file from remote to local ????????????????
#sftp.get('firewall.sh', '/tmp/firewall.sh')
# Upload file from local to remote ????????
#sftp.put('D:/iso/auto.sh', '/home/testssh/auto.sh')
except Exception, e:
print 'authentication failed or execute commands failed:',e
#dropdatabase("172.30.121.54","webui","123456","drop database frontend")
#sql_init("172.30.121.54", "root", "teamsun", "mysql -uwebui -p123456 < /etc/frontend/frontend.sql")
评论列表
文章目录