[SOLVED] Run guest agent commands on linux VM

foadk

Member
Mar 25, 2020
19
0
6
35
Hi.
I'm having trouble running commands using guest agent on a centos 7 VM.
I have installed qemu-guest-agent on VM and it's running. (tested via qm agent $VMID ping)
Problem is I can't execute arbitrary commands from host.
I've tried it in different forms but all failed:

Bash:
qm guest exec 384194 /bin/bash "ls"
{
   "err-data" : "/usr/bin/ls: /usr/bin/ls: cannot execute binary file\n",
   "exitcode" : 126,
   "exited" : 1
}

qm guest exec 384194 /bin/bash "echo hello"
{
   "err-data" : "/bin/bash: echo hello: No such file or directory\n",
   "exitcode" : 127,
   "exited" : 1
}

qm guest exec 384194 /bin/bash "echo" "hello"
{
   "err-data" : "/usr/bin/echo: /usr/bin/echo: cannot execute binary file\n",
   "exitcode" : 126,
   "exited" : 1
}

qm guest exec 384194 /bin/bash "-c" "echo" "hello"
Unknown option: c
400 unable to parse option
qm guest exec <vmid> [<extra-args>] [OPTIONS]

In last case, it recognizes "-c" as an option for "qm guest exec", not a bash option.
So how should I run commands using qm guest exec?
 
Hi.
I'm having trouble running commands using guest agent on a centos 7 VM.
I have installed qemu-guest-agent on VM and it's running. (tested via qm agent $VMID ping)
Problem is I can't execute arbitrary commands from host.
I've tried it in different forms but all failed:

Bash:
qm guest exec 384194 /bin/bash "ls"
{
   "err-data" : "/usr/bin/ls: /usr/bin/ls: cannot execute binary file\n",
   "exitcode" : 126,
   "exited" : 1
}

qm guest exec 384194 /bin/bash "echo hello"
{
   "err-data" : "/bin/bash: echo hello: No such file or directory\n",
   "exitcode" : 127,
   "exited" : 1
}

qm guest exec 384194 /bin/bash "echo" "hello"
{
   "err-data" : "/usr/bin/echo: /usr/bin/echo: cannot execute binary file\n",
   "exitcode" : 126,
   "exited" : 1
}

qm guest exec 384194 /bin/bash "-c" "echo" "hello"
Unknown option: c
400 unable to parse option
qm guest exec <vmid> [<extra-args>] [OPTIONS]

In last case, it recognizes "-c" as an option for "qm guest exec", not a bash option.
So how should I run commands using qm guest exec?
Code:
qm guest exec 384194 -- ls
 
  • Like
Reactions: Sourcenux
@che
That is not what I'm looking for. Sometimes it's going to be a very big command, like multiple commands concated with &&. like echo "something" >> file.txt && mv some-file other-file && ...
I can do that on a windows guest like so:
Code:
qm guest exec 384285 "C:\WINDOWS\system32\cmd.exe" "/c any command"
But I don't know how to do it for linux guest
 
Last edited:
@che
That is not what I'm looking for. Sometimes it's going to be a very big command, like multiple commands concated with &&. like echo "something" >> file.txt && mv some-file other-file && ...
I can do that on a windows guest like so:
Code:
qm guest exec 384285 "C:\WINDOWS\system32\cmd.exe" "/c any command"
But I don't know how to do it for linux guest
By simple deduction from the previous command I posted you will get
Code:
qm guest exec 384285 -- bash -c "echo hello; echo world"
 
Last edited:

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!