1

I'm trying to copy a few tarballs over an ssh session, but during the exec_command of

tar xzf ...

I see recv_exit_status of 2, even when writing a custom ssh_env file and sourcing it on the machine. I can give the remote machine the absolute path of the tar executable, but the problem persists. How might I fix this, or gather more information to help others help me?

Edit: for what it's worth, I believe the problem is related to the fact that tar implicitly invokes gzip

Edit re: Martin, the stderr is as follows

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

relevant code snippet:

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'))

where sshenv is a file as follows, that I have SCP'd over as well:

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
ILoveCliques
  • 135
  • 1
  • 11

0 Answers0