[SOLVED] pct exec/lxc-attach not working, 1839

marissachan

Member
Dec 30, 2021
7
6
8
29
Germany
I am currently trying to write a shell-script, that runs on the Proxmox-Host and executes different commands in containers. I would like to avoid using ssh and instead use pct exec directly.

But when I try to do that I get an error:
Bash:
root@Azusa:~# pct exec 200 "echo test"
lxc-attach: 200: ../src/lxc/attach.c: lxc_attach_run_command: 1839 No such file or directory - Failed to exec "echo test"

I already tried different variatons, like /bin/sh echo test, /bin/bash -c echo test or /bin/echo pacman for the command that should be executed within the container, but none of them works.

In the code I found this: https://github.com/lxc/lxc/blob/master/src/lxc/attach.c#L1841 but that does not help me much further.

Trying to search for that issue I found following threads:
https://forum.proxmox.com/threads/run-a-script-residing-in-a-container-using-pct-exe.68637/
Sadly the response does not seem to really help me?

https://forum.proxmox.com/threads/run-a-script-on-all-container-from-host.27478/#post-138404
Especially the
Just remember that the shell you're using has to exist in all containers under the same path (so you best use `#!/usr/bin/env bash` or something as shebang line...)
seems important? But I did try to take care of that. The script I am trying to execute uses the suggested shebang, but that does not seem to help, and the shell should exist. Executing /usr/bin/env | grep SHELL on both the host and within the containers returns SHELL=/bin/bash and that bash exists everywhere.

If I look at this script https://github.com/morph027/pve-lxc-scripts/blob/master/lxc-update-all then it seems like I should be doing everything correctly?

I use latest Debian and Arch Linux in my containers, and I currently have all updates (including the opt-in 6-Kernel) installed on the host.
 
Ah, I figured it out. I need to use two between the container id and the command itself, for example
pct exec 200 -- echo test
I guess the thread can be closed.
 
  • Like
Reactions: mbx