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

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

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

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

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

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 不生效的問題的文章就介紹到這了,更多相關(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)文章:
主站蜘蛛池模板: 重庆市| 沙坪坝区| 贵南县| 松桃| 两当县| 苗栗县| 黄龙县| 井陉县| 五台县| 岳池县| 阿勒泰市| 阳江市| 临汾市| 西平县| 花莲市| 内黄县| 开封市| 四会市| 土默特右旗| 枣强县| 卢龙县| 永定县| 仁怀市| 上杭县| 太白县| 顺平县| 栾川县| 繁峙县| 抚远县| 宜州市| 山阴县| 高要市| 会昌县| 青岛市| 锡林郭勒盟| 德钦县| 博白县| 江津市| 龙游县| 玉环县| 瑞金市|