久久福利_99r_国产日韩在线视频_直接看av的网站_中文欧美日韩_久久一

您的位置:首頁技術文章
文章詳情頁

解決Python paramiko 模塊遠程執行ssh 命令 nohup 不生效的問題

瀏覽:108日期:2022-07-17 14:26:00

Python - paramiko 模塊遠程執行ssh 命令 nohup 不生效的問題解決

1、使用 paramiko 模塊ssh 登陸到 linux 執行nohup命令不生效

# 執行命令def command(ssh_config, cmd, result_print=None, nohup=False): ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.connect(hostname=ssh_config.hostname, port=ssh_config.port, username=ssh_config.username,password=ssh_config.password) print(ssh_config.hostname + ’@’ + ssh_config.username, ’: ’, cmd) stdin, stdout, stderr = ssh.exec_command(cmd) result = stdout.read() if result_print: lines = read_unicode(result) for line in lines: print(line) ssh.close()

因為執行完畢后,shell 會立即關閉通道

2、稍作修改,使用 invoke_shell

# 執行命令def command(ssh_config, cmd, result_print=None, nohup=False): ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.connect(hostname=ssh_config.hostname, port=ssh_config.port, username=ssh_config.username,password=ssh_config.password) print(ssh_config.hostname + ’@’ + ssh_config.username, ’: ’, cmd) if nohup: cmd += ’ & n ’ invoke = ssh.invoke_shell() invoke.send(cmd) # 等待命令執行完成 time.sleep(2) else: stdin, stdout, stderr = ssh.exec_command(cmd) result = stdout.read() if result_print: lines = read_unicode(result) for line in lines:print(line) ssh.close()

到此這篇關于解決Python paramiko 模塊遠程執行ssh 命令 nohup 不生效的問題的文章就介紹到這了,更多相關Python paramiko 模塊遠程執行ssh 命令 nohup 不生效內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!

標簽: Python 編程
相關文章:
主站蜘蛛池模板: 一区二区免费视频观看 | 欧美色综合 | 91免费观看 | 亚洲欧美在线综合 | 国产一区二区三区视频在线观看 | 国产精品美女久久久久aⅴ国产馆 | 色综合成人 | 中文字幕在线免费观看 | 2019国产精品 | 成人h视频| 精品视频一区二区三区在线观看 | 国产又粗又长又硬又猛电影 | 黄色免费成人 | 国产一区二区综合 | 免费视频爱爱太爽了 | 成人精品视频在线观看 | 一二三区av | 久久这里只有精品首页 | 成人黄色在线观看 | 色婷婷一区二区三区四区 | 欧美精品a∨在线观看不卡 欧美日韩中文字幕在线播放 | 一二区精品 | 好色视频在线观看 | 黄a视频| 精品九九九 | 久久99国产一区二区三区 | 2018狠狠干| 亚洲一区二区福利 | 成人网址在线观看 | 国产精品久久久久久久久免费 | 一区二区三区在线 | 欧 | 国产精品久久久久久亚洲调教 | 成人国产 | 欧美精品久久久久 | 69性欧美高清影院 | 亚洲精品久久久久久久久久久久久 | 天天插天天狠 | 九九视频网 | 欧美猛交ⅹxxx乱大交视频 | 精品国产视频 | 亚洲国产天堂久久综合 |