Guest Agent Exec ">" Problem

UgurBurak

New Member
Aug 2, 2021
5
0
1
20
Hi everyone.

I developing Proxmox automation module for WHMCS. I want to add exec command from panel. I can execute commands fine. But when i want to write file this output with bash redirection I have a error.

This error be like in PHP code with var_export function:
PHP:
array ( 'exited' => 1, 'err-data' => 'date: extra operand â/home/denemedir.txtâ Try \'date --help\' for more information. ', 'exitcode' => 1, )

I try PHP code and CLI.

My PHP code:

PHP:
$path = "/nodes/{$node}/qemu/{$vmid}/agent/exec";
$data = [
    'command' => 'date > /home/denemedir.txt',
];

$send_command = $pve->post($path, $data);
if($send_command === false){
    logActivity(var_export($pve->debugInfo, true), 0);
}
while(true){
    $path = "/nodes/{$node}/qemu/{$vmid}/agent/exec-status?pid=".$send_command['pid'];
    $check_command = $pve->get($path, []);
    if($check_command === false){
        logActivity(var_export($pve->debugInfo, true), 0);
        break;
    }
    if($check_command['exited'] == 1){
        break;
    }
}
logActivity(var_export($check_command, true), 0);
$get_output = $pve->get("/nodes/{$node}/qemu/{$vmid}/agent/file-read?file=/root/denemedir.txt", []);
logActivity(var_export($get_output, true), 0);
if($get_output === false){
    logActivity(var_export($pve->debugInfo, true), 0);
}


and CLI command:
PHP:
pvesh create /nodes/server/qemu/3258/agent/exec --command "date > denemedir.txt"



I had this error in CLI:
PHP:
pvesh create /nodes/server/qemu/3258/agent/exec --command "date > denemedir.txt"
Wide character in die at /usr/share/perl5/PVE/RESTHandler.pm line 869.
Agent error: Guest agent command failed, error was 'Failed to execute child process “date > denemedir.txt” (No such file or directory)'


How can i solve it?
Thank you.
 
Last edited:
I'm trying another combinations in cli. Unfortunately i can't execute command with bash redirection.
I had this error:
1627934750655.png
 
The command is executed directly, not inside a shell - so you simply cannot use bash redirection.
 
well, yes you can, but you have to invoke the shell yourself:

Code:
.../exec --command 'sh' --command '-c' --command "date > deneme.txt"
 
  • Like
Reactions: UgurBurak
The command is executed directly, not inside a shell - so you simply cannot use bash redirection.
Okay. For example, i want to execute plesk's one click installer with qemu agent. How can i do?

This code has a bash redirection:
Code:
sh <(curl https://autoinstall.plesk.com/one-click-installer || wget -O - https://autoinstall.plesk.com/one-click-installer)
 
well, yes you can, but you have to invoke the shell yourself:

Code:
.../exec --command 'sh' --command '-c' --command "date > deneme.txt"
Hi again.
I'm trying in PHP code and REST HTTP API with your example. But i getting an error in PHP code but i dont get an error in shell with pvesh api.

Am I have to create a bash file and run to be success?

Error:
Code:
>: 1: Syntax error: Unterminated quoted string

My latest code:
PHP:
                                    $code = str_replace('&gt;', '>', $isExist->code);
                                    $code = str_replace('&lt;', '<', $code);
                                    $code = str_replace('&amp;', '&', $code);
                                    $path = "/nodes/{$node}/qemu/{$vmid}/agent/exec";
                                    $data = [
                                        'command' => "sh -c \"{$code}\"",
                                    ];

                                    $send_command = $pve->post($path, $data);
 
Hi again.
My problem is continue. Now, i trying with Centos but i can't file-write process in Centos. I must use this command because i can't use directly or with "sh -c". If i use each one, i getting an error.

Example, i want to install plesk with one click installer command, i can doing it in Ubuntu with file-write and execute process. But, when i try this method in Centos, i cant. Because Centos devs disabled this command.

How can i install plesk or cPanel in Centos with Qemu-Agent? How can i execute oneclick installer commands?

My Plesk command:
Code:
sh <(curl https://autoinstall.plesk.com/one-click-installer || wget -O - https://autoinstall.plesk.com/one-click-installer)

cPanel Command
Code:
cd /home && curl -o latest -L https://securedownloads.cpanel.net/latest && sh latest
 
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!