From a17ee366f1afddf892ad835b25ee635eb7be7f51 Mon Sep 17 00:00:00 2001 From: witchc Date: Wed, 27 Oct 2021 19:58:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20execute/execfile=20sudo=20?= =?UTF-8?q?=E9=80=89=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pypssh.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pypssh.py b/pypssh.py index 6cae151..8c5e524 100644 --- a/pypssh.py +++ b/pypssh.py @@ -419,6 +419,9 @@ def execute(command, needpty, sudo, outmode, template): """ execute command """ + if sudo: + for i in TARGET: + i.sudo = sudo result = [] if needpty: result = concurrent( @@ -468,10 +471,10 @@ def execfile(ctx, script_file, script_arg, env, attachment, workdir, needpty, su script_env = ''.join(["export %s && " % item for item in env]) script_arg_str = ' '.join(script_arg) command = f"{script_env} cd {workdir} && chmod +x {remote_file} && {remote_file} {script_arg_str}" - ctx.invoke(execute, command=command, outmode=outmode, template=template) + ctx.invoke(execute, command=command, outmode=outmode, template=template, sudo=sudo) finally: command = f"rm -rf {' '.join(put_files)}" - ctx.invoke(execute, command=command, outmode=outmode, template=template) + ctx.invoke(execute, command=command, outmode=outmode, template=template, sudo=sudo) put_default_template = "{{src}} =====> {{hostname}}:{{dst}} {% if completed %} successfully! {% else %} faild! {% endif %}"