1

I tried the following command, but only an empty file is created on the target and the command stays open

qemu-img convert -f raw -O vmdk /dev/sda1 - | ssh foo@bar "cat > /home/foo/foobar.vmdk"

Note: sshfs is not available.

mgutt
  • 459
  • 6
  • 22

1 Answers1

1

You want to use tee instead of cat.

tee - read from standard input and write to standard output and files

qemu-img convert -f raw -O vmdk /dev/sda1 - | ssh foo@bar "tee /home/foo/foobar.vmdk > /dev/null"
Gerald Schneider
  • 19,757
  • 8
  • 52
  • 79
  • I've tried it locally, but the file stays empty `qemu-img convert -f raw -O vmdk /dev/sda1 - | tee "/home/foo/foobar.vmdk" > /dev/null` – mgutt Nov 10 '21 at 10:56
  • Did you check if a file called `-` was created? Using `-` for stdout is a convention, but it's not available in every tool. I found [this old mailing list entry](https://linux.debian.bugs.dist.narkive.com/PGRdZGYQ/bug-513451-qemu-img-add-stdin-stdout-support) where it is stated that `This is technically not possible. Given the formats involved, the file is not read/written linearly, which render the use of stdin/stdout impossible`. If that hasn't changed since It might simply not be possible to pipe the result of qemu-img to stdout. – Gerald Schneider Nov 10 '21 at 11:04
  • Couldn't down vote because of missing points but this answer is wrong. Using cat is totally fine and using tee with piping stdout to dev null shouldn't help at all here. – thomas Jun 20 '22 at 15:54
  • Though the comment regarding using `-` for `/dev/stdout` explains what happend. `qemu-img` just wrote the output into a file called `-`. If you 180° your answer to reflect that you can have my upvote. – thomas Jun 20 '22 at 16:01