[lxc-users] lxd lxc exec command to container tries to execute on Host instead?
Stéphane Graber
stgraber at ubuntu.com
Mon Jan 4 16:51:58 UTC 2016
Hi,
Your problem is a misunderstanding of shell glob expansion.
The *.sh is expanded on the machine you're running the command on, then
the expanded form of the command is spawned by the shell, that's why
you're seeing host paths when running it.
lxc exec cn1 -- sh -c "chmod +x /home/$USER/*.sh"
That one will actually run "chmod +x /home/$USER/*.sh" on the target
container and let the container's shell expand $USER and *.sh in the
container rather than on the client.
On Mon, Jan 04, 2016 at 11:46:39AM -0500, brian mullan wrote:
> I was working on a bash script to automate some LXD/LXC container setups.
>
> I successfully created the container cn1
>
> I successfully added a new User to cn1
>
> I successfully PUSHed several script files to the Home directory of the new
> User in CN1
>
> However, when I try to chmod +x those scripts using:
>
>
>
> * lxc exec cn1 -- chmod +x /home/$USER/*.sh*it seems to be trying to
> do it on the Host instead & fails!
>
> I have searched but can't find a reason why or if I am using the exec
> command wrong.
>
> A snippit of my Host script is below:
>
>
>
> * lxc remote add images images.linuxcontainers.org
> <http://images.linuxcontainers.org> # this works*
>
> * # launch as a Priviliged container *
>
>
>
>
>
>
>
>
>
>
>
>
>
> * lxc launch images:ubuntu/wily/amd64 cn1 -c security.privileged=true #
> this works # create the new User in BOTH cn1 container lxc exec cn1 - -
> adduser $USER # this works
> #----------------------------------------------------------------------------------------------------------------
> # Next pushing the appropriate script to its now running container.
> #-----------------------------------------------------------------------------------------------------------------
> lxc file push ./mk-cn1-environment.sh cn1/home/$USER/ # this works #
> make sure bash scripts we pushed are executable -- THIS FAILS lxc exec
> cn1 - - chmod +x /home/$USER/*.sh*
>
>
> That last command outputs the following error messages:
>
>
>
>
> * $ lxc exec cn1 -- chmod +x /home/$USER/*.sh chmod: cannot access
> '/home/bmullan/createlxc.sh': No such file or directory chmod: cannot
> access '/home/bmullan/deletelxc.sh': No such file or directory chmod:
> cannot access '/home/bmullan/mkcn.sh': No such file or directory*
>
>
> However, those .sh files are on my Host in /home/bmullan NOT the ones I
> pushed
> to cn1 in /home/bmullan ?
>
> Am I using lxc exec incorrectly somehow ?
>
> thanks for any advice.
>
> Brian
> _______________________________________________
> lxc-users mailing list
> lxc-users at lists.linuxcontainers.org
> http://lists.linuxcontainers.org/listinfo/lxc-users
--
Stéphane Graber
Ubuntu developer
http://www.ubuntu.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.linuxcontainers.org/pipermail/lxc-users/attachments/20160104/3d79ab0f/attachment.sig>
More information about the lxc-users
mailing list