0

Hi I am trying to automate lxc container creation/starting/stopping and executing commands inside them via script (Bash/Python). I was able to create a container which is a very simple step

lxc-create -t ubuntu -n CONTAINER1

Now I want to start this container and login to it using a script. I tried expect to pass the username and password which did not work.

lxc-start -n CONTAINER1

Any ideas would be appreciated.

Santhosh
  • 891
  • 3
  • 12
  • 31

1 Answers1

0

First, start the container with the -d option in a script, then call the script below.

I create a small script with "expect" that can login the container, perform a ls -tral and then logout.

#!/usr/bin/expect
spawn ssh root@CONTAINER1
expect "password" {
  send "root\r" }
expect "# " {send "ls -tral\r" }
expect "# " {send "logout\r" }

And yes, the default password for root is root, and yes, on my systems I changed them al :-)

Jaap D
  • 501
  • 5
  • 18