Proxmox execute command

x86

New Member
Aug 19, 2014
21
0
1
Dear,

Again a few problems with the API. I am unable to send shell commands to the proxmox host via the API.
i.e.
PHP:
$aCommands = array
(
    'pct exec ' . $iVMID . ' -- ls -al /'
);

var_dump ( $pApi->post ( '/nodes/' . $sNodeName . '/execute', array ( 'commands' => json_encode ( $aCommands ) ) ) );

The result will be:
array(1) {
[0]=>
array(2) {
["status"]=>
int(500)
["message"]=>
string(96) "pct exec 106 -- ls -al / is not a valid command at /usr/share/perl5/PVE/API2/Nodes.pm line 352.
"
}
}

Executing this command via putty works like a charm.

I cant also change special config vars of my LXC container via the API, i.e.
lxc.aa_profile: lxc-custom-mounts

Can someone help? Thanks.
 

dietmar

Proxmox Staff Member
Staff member
Apr 28, 2005
17,137
533
133
Austria
www.proxmox.com
Again a few problems with the API. I am unable to send shell commands to the proxmox host via the API.

The "/nodes/<NodeName>/execute" API call allows you to execute multiple API calls at once. It is not meant to execute arbitrary shell commands. I guess you should use ssh if you really want to do that.

What do you want to do exactly? Execute shell commands inside containers?
 

x86

New Member
Aug 19, 2014
21
0
1
What do you want to do exactly? Execute shell commands inside containers?

Ok thanks for the information. I created a script which deploys new LXC for customers. I did configure a CIFS share mount via DAB within the template (thats why I need to use the special config var; 'lxc.aa_profile: lxc-custom-mounts'). After creation I need to do a post deployment (install specific software for the customer, that's why I want to execute a script inside the container.
 

Philipp Page

Member
Apr 26, 2016
30
0
6
25
I also want to execute commands inside a container via the api. Is there an other solution than establishing an ssh connection to the node?
 

dietmar

Proxmox Staff Member
Staff member
Apr 28, 2005
17,137
533
133
Austria
www.proxmox.com
I also want to execute commands inside a container via the api. Is there an other solution than establishing an ssh connection to the node?

Currently not. But I would directly connect (ssh) to the container instead.
 

Philipp Page

Member
Apr 26, 2016
30
0
6
25
Yes, but i dont know the password since i am using this api for client vms. I only want to be able to enable root login with password after creating a container. I want to execute the replace command on the host therefore
 

bert2

Member
Jun 5, 2016
2
0
6
44
I also looked for a solution. Because some of the default images for containers contain only root accounts. A direct container ssh is only possible after adding an additional user (or enabling ssh for root). So in my ansible automation I just want to add a user to the container via the proxmox api after creating a new container. Currently I have to do it via the "console" manually or using the "pct exec" command via ssh, ...
 

dietmar

Proxmox Staff Member
Staff member
Apr 28, 2005
17,137
533
133
Austria
www.proxmox.com
I also looked for a solution. Because some of the default images for containers contain only root accounts. A direct container ssh is only possible after adding an additional user (or enabling ssh for root).

We added a new parameter called "--ssh-public-keys" to the the api/cli, see

# pct help create

I thought this solves the problem with ansible?
 

bert2

Member
Jun 5, 2016
2
0
6
44
No it "only" adds ssh_keys from a file to the root account. At least I didn't manage to add keys to another account within the container. And if I got it right on command line, not via the api.
 
Last edited:

fabian

Proxmox Staff Member
Staff member
Jan 7, 2016
8,150
1,592
164
Yes, it only adds the keys to the root account. The rest is up to your automation tools ;)
 
  • Like
Reactions: Philipp Page

Medvenda

Member
Oct 5, 2016
40
0
6
35
Hello,
I need to execute a shell command in node via API to delete the rrdcached file "/var/lib/rrdcached/db/pve2-vm" for VM when i delete the VM because i have the old stats for a VM which is replaced with another (same ID).
Any suggestion to solve this problem ?
 

dietmar

Proxmox Staff Member
Staff member
Apr 28, 2005
17,137
533
133
Austria
www.proxmox.com
Please note that those statistics are replicated to all cluster nodes, so you would need to remove them on all nodes.
 

Medvenda

Member
Oct 5, 2016
40
0
6
35
i don't have a cluster between nodes, i like just to fond a way to delete the rrdcached file when i remove a VM.
It's possible ? or i must change the API code ? thanks
 

Medvenda

Member
Oct 5, 2016
40
0
6
35
Please note that those statistics are replicated to all cluster nodes, so you would need to remove them on all nodes.
i don't have a cluster between nodes, i like just to fond a way to delete the rrdcached file when i remove a VM.
It's possible ? or i must change the API code ? thanks
 

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 your own in 60 seconds.

Buy now!