From 18313b286cd7b07092ce4e5fe5a16833367a4905 Mon Sep 17 00:00:00 2001 From: vapao Date: Sun, 26 Jun 2022 22:10:13 +0800 Subject: [PATCH] =?UTF-8?q?A=20=E6=B7=BB=E5=8A=A0=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=88=86=E5=8F=91=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spug_api/apps/exec/transfer.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/spug_api/apps/exec/transfer.py b/spug_api/apps/exec/transfer.py index b4e55b2..5e4b64a 100644 --- a/spug_api/apps/exec/transfer.py +++ b/spug_api/apps/exec/transfer.py @@ -106,13 +106,19 @@ def _do_sync(rds, task, host): fp.flush() options = '-azv' if task.host_id else '-rzv' - target = f'{host.username}@{host.hostname}:{task.dst_dir}' - command = f'rsync {options} -h -e "ssh -p {host.port} -i {fp.name}" {task.src_dir}/ {target}' + argument = f'{task.src_dir}/ {host.username}@{host.hostname}:{task.dst_dir}' + command = f'rsync {options} -h -e "ssh -p {host.port} -o StrictHostKeyChecking=no -i {fp.name}" {argument}' task = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) while True: message = task.stdout.readline() if not message: break message = message.decode().rstrip('\r\n') + if 'rsync: command not found' in message: + data = '\r\n\x1b[31m检测到该主机未安装rsync,可通过批量执行/执行任务模块进行以下命令批量安装\x1b[0m' + data += '\r\nCentos/Redhat: yum install -y rsync' + data += '\r\nUbuntu/Debian: apt install -y rsync' + rds.publish(token, json.dumps({'key': host.id, 'data': data})) + break rds.publish(token, json.dumps({'key': host.id, 'data': message + '\r\n'})) rds.publish(token, json.dumps({'key': host.id, 'status': task.wait()}))