Not sure if this is a bug or a feature request.
I wanted to execute this command:
lxc exec u1604 -- 'ls -l / > /tmp/ls'
but I did not manage to run a command on the container that redirects it output to a file on the container.
I tried some other variants as well (double quotes, escaping the >, trying "bash ls -l > /tmp/ls", ...) but to no avail
Is this a bug? Am I missing something ?
(I know I can work around this by capturing the output of the command in a local file then copy that file over to the container but that does not look too efficient)
lxc exec alp3 -- sh -c "ls -al > /tmp/test" should do the trick.
Thanks! That worked.
Do you want me to close the issue or is there some development you want to do for this?
(Maybe it would be nice to add your lxc exec line somewhere to the documentation.
I don't think there's a lot we can/want to do about this. :)
ok, thanks for your help!
Right, "lxc exec" doesn't use a shell, it uses exec, so shell patterns (variables, file redirects, ...) won't be understood by the kernel, typically leading to no output being printed and a non-zero return value from the command.
In your case, the kernel would have tried to execute the "/ls -l / > /tmp/ls" path which obviously doesn't exist. "sh -c" as suggested by @brauner is how you get things ran through the shell.
Got it. Thanks for the explanation!
This would be something that should be mentionend in the docs as it just took me quite a long time to figure it out.
Most helpful comment
lxc exec alp3 -- sh -c "ls -al > /tmp/test"should do the trick.