亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

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

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

瀏覽:109日期: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 編程
相關文章:
主站蜘蛛池模板: 国产在线精品观看一区 | 亚洲国产日韩a在线播放 | 能免费看黄的网站 | 香蕉视频黄色 | 国产一区系列在线观看 | 日韩在线视频不卡一区二区三区 | 欧美一欧美一区二三区性 | 国产日产欧产美一二三区 | 精品久久国产视频 | 国产成人免费在线视频 | 久久精品国产一区二区 | 精品国产福利在线观看91啪 | 日本免费黄网站 | 国产精品成人免费福利 | 玖玖国产精品视频 | 久久久久亚洲精品中文字幕 | 国产在线一区二区杨幂 | 精品视频在线观看你懂的一区 | 国产日韩在线观看视频网站 | 国产精品日韩欧美 | 1313午夜精品久久午夜片 | 伊人手机在线视频 | 99草视频| 青草国产精品久久久久久 | 国产精品情侣久久婷婷文字 | 亚洲国产欧美日韩 | 日韩欧美一区二区三区视频 | 国产精品免费大片 | 亚洲一色 | 国产成人刺激视频在线观看 | 91视频免费观看 | 丁香婷婷综合五月综合色啪 | 欧美日韩三区 | 一级片视频免费观看 | 一级片免费网站 | 九九热视频这里只有精品 | 亚洲色图在线观看视频 | 中国护士一级毛片免费版本 | 亚洲综合美腿丝国产一区 | 国产免费观看网站黄页 | 国产成人ae在线观看网站站 |