PHP PVE2 api send guest command

bitwiseyazilim

New Member
Dec 30, 2022
3
0
1
Hello there,

I am developing an automation on automatic server setup via php.

all stages are ok, as the last process, we need to send commands such as password update, ip change and extra package installations in the server.

I figured out that I would use the /api2/json/nodes/{node}/qemu/{vmid}/agent/exec directory path. but i don't understand how to use it exactly.

I'm able to work with the following command over ssh, but I couldn't figure out how to send the same commands via pve2 php api.

qm guest exec 111 -- "/bin/bash" "-c" "cat /etc/resolv.conf"


sample code

Code:
$params = array(
    "command" => array(
        "--",
        "/bin/bash",
        "-c",
        "cat /etc/resolv.conf"
    )
);

var_dump($pve2->post("/nodes/pve10/qemu/111/agent/exec",$params));
 
i solved it.
if anyone is wondering

Code:
$command = "sed -i 's/test1/test2/g' /root/text.txt";

$params = array(
    "command" => "/bin/bash",
    "input-data" => $command,
);

var_dump($pve2->post("/nodes/$get_parameter->node/$get_parameter->type/$get_parameter->vm_id/agent/exec",$params));
 
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!