Skip to content

Commit

Permalink
F 修复zsh批量执行异常问题 #522
Browse files Browse the repository at this point in the history
  • Loading branch information
vapao committed Jul 14, 2022
1 parent db38454 commit 808ae4e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 5 additions & 0 deletions spug_api/apps/exec/executors.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
# Copyright: (c) <[email protected]>
# Released under the AGPL-3.0 License.
from django_redis import get_redis_connection
from libs.utils import human_seconds_time
from libs.ssh import SSH
import threading
import socket
import json
import time


def exec_worker_handler(job):
Expand Down Expand Up @@ -51,12 +53,15 @@ def run(self):
if not self.token:
with self.ssh:
return self.ssh.exec_command(self.command, self.env)
flag = time.time()
self.send('\r\n\x1b[36m### Executing ...\x1b[0m\r\n')
code = -1
try:
with self.ssh:
for code, out in self.ssh.exec_command_with_stream(self.command, self.env):
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:
code = 130
self.send('\r\n\x1b[31m### Time out\x1b[0m')
Expand Down
3 changes: 2 additions & 1 deletion spug_api/libs/ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ def _get_channel(self):

counter = 0
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)
self.channel.sendall(command)
out = ''
Expand Down

0 comments on commit 808ae4e

Please sign in to comment.