Re: [lxc-users] lxc exec - support for wildcards and/or variables?
lxc exec $CONTAINER -- bash -c "rm -rf /tmp/somefile*" On 11/17/2017 08:03 AM, Tomasz Chmielewski wrote: How do I use the variables / wildcards with lxc exec? Say, I want to remove all /tmp/somefile* in the container. ___ lxc-users mailing list lxc-users@lists.linuxcontainers.org http://lists.linuxcontainers.org/listinfo/lxc-users
Re: [lxc-users] lxc exec - support for wildcards and/or variables?
Greetings, Tomasz Chmielewski! > lxc exec does not seem to support wildcards: It's not exec, it's you. > # lxc exec $CONTAINER -- touch /tmp/file1 /tmp/file2 > # lxc exec $CONTAINER -- ls /tmp/file* > ls: cannot access '/tmp/file*': No such file or directory > # lxc exec $CONTAINER -- ls /tmp/file\* > ls: cannot access '/tmp/file*': No such file or directory Of course. lxc exe does exactly what you said to do. > So let's try by setting a variable, which works: > # lxc exec --env LSFILES=/tmp/file* $CONTAINER -- env > PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin > container=lxc > TERM=xterm-256color > USER=root > HOME=/root > LSFILES=/tmp/file* <- it's set, here! > LANG=C.UTF-8 > But how to use it from lxc exec? > - this obviously gets expanded on the host: > # lxc exec --env LSFILES=/tmp/file* $CONTAINER -- echo $LSFILES > - this is passed as a literal $LSFILES to the container: > # lxc exec --env LSFILES=/tmp/file* $CONTAINER -- echo \$LSFILES > $LSFILES > How do I use the variables / wildcards with lxc exec? Say, I want to > remove all /tmp/somefile* in the container. Do what your host do - allow shell to expand in the container. Since wildcard expansion is done by the shell (surprize!), not by the executed program, you'd have to run the command through shell in the container. Which you are not doing currently. Same as if you run "ls '/tmp/file*' " on host. -- With best regards, Andrey Repin Saturday, November 18, 2017 07:45:47 Sorry for my terrible english... ___ lxc-users mailing list lxc-users@lists.linuxcontainers.org http://lists.linuxcontainers.org/listinfo/lxc-users
[lxc-users] lxc exec - support for wildcards and/or variables?
lxc exec does not seem to support wildcards: # lxc exec $CONTAINER -- touch /tmp/file1 /tmp/file2 # lxc exec $CONTAINER -- ls /tmp/file* ls: cannot access '/tmp/file*': No such file or directory # lxc exec $CONTAINER -- ls /tmp/file\* ls: cannot access '/tmp/file*': No such file or directory So let's try by setting a variable, which works: # lxc exec --env LSFILES=/tmp/file* $CONTAINER -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin container=lxc TERM=xterm-256color USER=root HOME=/root LSFILES=/tmp/file* <- it's set, here! LANG=C.UTF-8 But how to use it from lxc exec? - this obviously gets expanded on the host: # lxc exec --env LSFILES=/tmp/file* $CONTAINER -- echo $LSFILES - this is passed as a literal $LSFILES to the container: # lxc exec --env LSFILES=/tmp/file* $CONTAINER -- echo \$LSFILES $LSFILES How do I use the variables / wildcards with lxc exec? Say, I want to remove all /tmp/somefile* in the container. Tomasz Chmielewski https://lxadm.com ___ lxc-users mailing list lxc-users@lists.linuxcontainers.org http://lists.linuxcontainers.org/listinfo/lxc-users