def exec_cmd(host,cmds): ssh=paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) print '[%s] Connecting to %s ...'%(host,host) ssh.connect(host,22,username,password) for cmd in cmds: stdin,stdout,stderr=ssh.exec_command(cmd) t_out=async_out(host,stdout); t_err=async_err(host,stderr) t_out.join(); t_err.join() print_host(host,'Completed') ssh.close()
def exec_cmd(host, cmds): ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) print '[%s] Connecting to %s ...' % (host, host) ssh.connect(host, 22, username, password) for cmd in cmds: stdin, stdout, stderr = ssh.exec_command(cmd) t_out = async_out(host, stdout) t_err = async_err(host, stderr) t_out.join() t_err.join() print_host(host, 'Completed') ssh.close()
def copy_file(host,src,des): ssh=paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) print '[%s] Connecting to %s ...'%(host,host) ssh.connect(host,22,username,password) sftp=ssh.open_sftp() print_host(host,'Connected. Start transferring ...') for sn,fn in src.items(): sftp.put(fn,des+'/'+sn) print_host(host,fn+' copied') print_host(host,'Completed') ssh.close()