I am attempting to automate installation of Alpine Linux in vm-bhyve under FreeBSD and expect dies shortly after the boot menu times out and launches the Alpine Linux installation.
#!/usr/bin/env expect
spawn vm install -f alpine alpine.iso # shortened for brevity
expect "localhost login:"
send "root\r"
...
This results in the following error:
"while executing
"send "root\r"
I suspect that whenever the screen clears and it starts to boot, that confuses expect to think the program is done? And, as a result, the script dies.
I've never coded expect in this manner before, is it possible to do it with expect?
I also tried setting a global timeout before spawning the vm install cmd which boots and immediately goes into the console for the guest, but that didn't change anything so I excluded it from the script above. Sleep in the same spot didn't help, it just delayed booting (and subsequent failure by the amount I set for sleep).
EDIT: I am trying to launch the installer in the background, sleep 30s, then attach a console. At this point, Expect should work.
I have it working in both cases (vm install -f and using vm console to attach to a running VM).
The problem in my case was that I started with a fresh configuration and that fresh configuration had an invalid setting (PCI passthrough). I thought I had booted up without expect and had that working; however, I had already reimaged the machine and my configuration was overwritten.
Using autoexpect allowed me to capture more details that I would have had otherwise and is a great way to prepare expect scripts.
Now, the process for me is to perform a freebsd install followed by booting into the system and upon startup, check if the VMs exist, if not, create them using expect.