午夜剧场伦理_日本一道高清_国产又黄又硬_91黄色网战_女同久久另类69精品国产_妹妹的朋友在线

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

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

瀏覽:181日期: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亚洲国产成人精品一区二区三 | 欧美在线看 | 99久久婷婷国产精品综合 | 成人免费小视频 | 三级黄色片免费 | 看黄网站在线 | www.色婷婷.com | 亚洲视频在线观看视频 | 久久久久久成人 | 日韩成人区 | 久久激情视频 | 亚洲欧美a | 国产特级黄色片 | 久久精品91 | 精品有码 | 婷婷视频在线播放 | 国产精品视频自拍 | av超碰在线| 特级西西人体444是什么意思 | av青青草原 | 日韩三级视频在线播放 | 国产成人一级 | 国产成人三级在线播放 | 亚洲第一在线视频 | 黄色片一区二区三区 | 日韩免费一区二区三区 | 亚洲国产系列 | 日本高清www免费视频 | 永久免费黄色 | 国产福利专区 | 小明永久2015xxx免费看视频 | a久久久久| 亚洲九九色 | 免费看黄色一级视频 | 超碰2019| 久久久午夜精品 | 99国产精品99久久久久久粉嫩 | 婷婷狠狠操 | 黄色www| 你懂的视频在线 | 中文字幕在线日韩 |