F 修复zsh批量执行异常问题 #522

pull/586/head
vapao 2022-07-14 23:38:40 +08:00
parent db38454787
commit 808ae4e679
2 changed files with 7 additions and 1 deletions

View File

@ -2,10 +2,12 @@
# Copyright: (c) <spug.dev@gmail.com> # Copyright: (c) <spug.dev@gmail.com>
# Released under the AGPL-3.0 License. # Released under the AGPL-3.0 License.
from django_redis import get_redis_connection from django_redis import get_redis_connection
from libs.utils import human_seconds_time
from libs.ssh import SSH from libs.ssh import SSH
import threading import threading
import socket import socket
import json import json
import time
def exec_worker_handler(job): def exec_worker_handler(job):
@ -51,12 +53,15 @@ class Job:
if not self.token: if not self.token:
with self.ssh: with self.ssh:
return self.ssh.exec_command(self.command, self.env) return self.ssh.exec_command(self.command, self.env)
flag = time.time()
self.send('\r\n\x1b[36m### Executing ...\x1b[0m\r\n') self.send('\r\n\x1b[36m### Executing ...\x1b[0m\r\n')
code = -1 code = -1
try: try:
with self.ssh: with self.ssh:
for code, out in self.ssh.exec_command_with_stream(self.command, self.env): for code, out in self.ssh.exec_command_with_stream(self.command, self.env):
self.send(out) self.send(out)
human_time = human_seconds_time(time.time() - flag)
self.send(f'\r\n\x1b[36m** 执行结束,总耗时:{human_time} **\x1b[0m')
except socket.timeout: except socket.timeout:
code = 130 code = 130
self.send('\r\n\x1b[31m### Time out\x1b[0m') self.send('\r\n\x1b[31m### Time out\x1b[0m')

View File

@ -181,7 +181,8 @@ class SSH:
counter = 0 counter = 0
self.channel = self.client.invoke_shell(**self.term) self.channel = self.client.invoke_shell(**self.term)
command = 'set +o history\nset +o zle\nset -o no_nomatch\nexport PS1= && stty -echo\n' command = 'set +o zle\n[ -n "$BASH_VERSION" ] && set +o history\n[ -n "$ZSH_VERSION" ] && set -o no_nomatch\n'
command += 'export PS1= && stty -echo\n'
command = self._handle_command(command, self.default_env) command = self._handle_command(command, self.default_env)
self.channel.sendall(command) self.channel.sendall(command)
out = '' out = ''