国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

解決Python paramiko 模塊遠(yuǎn)程執(zhí)行ssh 命令 nohup 不生效的問(wèn)題

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

Python - paramiko 模塊遠(yuǎn)程執(zhí)行ssh 命令 nohup 不生效的問(wèn)題解決

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

# 執(zhí)行命令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()

因?yàn)閳?zhí)行完畢后,shell 會(huì)立即關(guān)閉通道

2、稍作修改,使用 invoke_shell

# 執(zhí)行命令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) # 等待命令執(zhí)行完成 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()

到此這篇關(guān)于解決Python paramiko 模塊遠(yuǎn)程執(zhí)行ssh 命令 nohup 不生效的問(wèn)題的文章就介紹到這了,更多相關(guān)Python paramiko 模塊遠(yuǎn)程執(zhí)行ssh 命令 nohup 不生效內(nèi)容請(qǐng)搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!

標(biāo)簽: Python 編程
相關(guān)文章:
主站蜘蛛池模板: 保康县| 涟水县| 基隆市| 大竹县| 枣庄市| 城步| 浮山县| 林甸县| 启东市| 庆云县| 名山县| 连云港市| 孟州市| 宜兴市| 庆城县| 新化县| 绍兴县| 同心县| 宁都县| 邯郸县| 启东市| 定日县| 新沂市| 巴青县| 麦盖提县| 信丰县| 寿宁县| 新乐市| 包头市| 多伦县| 丰城市| 舞钢市| 桃江县| 扶余县| 化德县| 西和县| 双牌县| 赤壁市| 和平区| 醴陵市| 平遥县|