How to? Create or edit file with qm guest agent

jmjosebest

Renowned Member
Jan 16, 2009
192
38
93
Hello,

I'm trying to create /test.file with a test content, inside a VM.

Running directly in the VM, normally I can do:

Code:
echo test > /test.file

So, I expected that running this will work...

Code:
qm guest exec 100 echo test -- "> /test.file"

But seems is not working...

There is any way to do?

Thanks!
 
Last edited:
Found a solution :)

Code:
pvesh create /nodes/ns1000/qemu/100/agent/file-write --content "$(echo -e 'test')" --file "/test.file"

But it's strange that we can not do this with qm agent...
 
yes you can do it but you have to use a different command
guest agent executes a single program, not a shell, so if you want to use shell redirection you have to manually invoke the shell, e.g.

Code:
qm guest exec 100 -- /bin/sh -c "echo test > /test.file"
 
  • Like
Reactions: waltar