我试图在ssh会话中复制一些tarball,但是在
的exec_command期间tar xzf ...
我看到recv_exit_status为2,即使在编写自定义ssh_env文件并在机器上获取它时也是如此。我可以给远程机器tar可执行文件的绝对路径,但问题仍然存在。我该如何解决这个问题,或者收集更多信息来帮助别人帮助我?
编辑:对于它的价值,我相信这个问题与tar隐式调用gzip这个事实相关
编辑重新:马丁,stderr如下
tar (child): file.tar.gz: cannot open: no such file or directory
tar (child): Error is not recoverable: exiting now
tar: Child returned status 2
tar: Error exit delayed from previous errors
相关代码段:
client = pmk.SSHClient()
client.load_system_host_keys()
client.connect(target, port=SSH_PORT, username="root", password="")
cur_file = "file.tar.gz"
commands = [
"cd tmp",
"tar zxf {} -C /app".format(cur_file)
]
]
for command in commands:
stdin, stdout, stderr = client.exec_command(". /tmp/sshenv ; {}".format(command))
print(stdout.read().decode('utf-8'))
if stdout.channel.recv_exit_status() == 0:
print("done!")
else:
print("ERROR: ", stderr.read().decode('utf-8'))
print("STDOUT: ", stdout.read().decode('utf-8'))
其中sshenv是一个如下文件,我也有SCP过了:
export _=/proc/boot/env
export PS1=$(hostname):$PWD #
export PATH=/proc/boot:/bin:/usr/bin:/sbin:/usr/sbin:/opt/bin:/flash/bin
export SHELL=/bin/sh
export USER=root
export MAIL=/var/spool/mail/root
export LD_LIBRARY_PATH=/proc/boot:/lib:/usr/lib:/lib/dll:/proc/boot:/opt/lib
export HOME=/
export TERM=xterm-256color
export SSH_TTY=/dev/ttyp0
export LOGNAME=root