LXD rest api /1.0/containers/<name>/exec

Hello. I can’t get multiple commands working. My request body object:
var body = { "command": [ "cd", "/var/www", "&&", "wget", "https://wordpress.org/latest.tar.gz" ], "environment": {}, "wait-for-websocket": false, "record-output": false, "interactive": true };
When I used this with just one command user add everything seems to be working, and if I use 2 commands, it don’t works. I know, that if I run in console I have to run lxc exec containerName -- sh -c "cd /var/www/&&wget https://wordpress.org/latest.tar.gz", but this:
var body = { "command": [ "sh", "-c", "'", "cd", "/var/www", "&&", "wget", "https://wordpress.org/latest.tar.gz", "'" ], "environment": {}, "wait-for-websocket": false, "record-output": false, "interactive": true };
doesn’t work either. What is correct way of executing multiple terminal commands in one request?

You want "command": ["sh", "-c", "cd /var/www && wget ..."]

That is, the argument after the sh -c must be the entire “script” that you want your shell to execute.

1 Like

Thank you