av一区二区在线观看_亚洲男人的天堂网站_日韩亚洲视频_在线成人免费_欧美日韩精品免费观看视频_久草视

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

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

瀏覽:121日期: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 | 高跟肉丝丝袜呻吟啪啪网站av | 亚洲在线免费观看 | 手机在线免费av | 国产福利视频 | 亚洲免费二区 | av大全在线观看 | 一本色道久久综合亚洲精品酒店 | 亚洲91精品 | 成人综合婷婷国产精品久久 | 国产成人精品亚洲男人的天堂 | 亚洲欧美日韩在线 | 欧美成人精品欧美一级私黄 | 久久久激情| 日韩美女一区 | 精品日韩在线观看 | 激情网五月天 | 五月婷婷色综合 | 日韩精品一区二区在线 | 亚洲不卡视频 | 国产永久精品 | 看国产毛片 | 欧洲av在线 | 日本免费在线视频 | 亚洲欧美精品在线 | 天堂中文av| 亚洲综合五月天婷婷丁香 | 对白刺激国产子与伦 | 老司机精品福利视频 | 黄色片91| 国产三级久久 | 国产乱淫av | 欧美一区二区精品 | 在线色| 久久精品一区二区三区四区五区 | 中文字幕免费av | 国产乱码一区二区 |