func checkInst(kingdom ,pass string) {
var z = fmt.Sprintf("rbs -k %v -r inst -a console", kingdom)
var x = fmt.Sprintf("scc -n ops0-host1-1-%v.eng.host.net &", kingdom)
child, err :=gexpect.Spawn(z)
if err != nil {
panic(err)
}
child.Expect("Escape character is ^]")
child.SendLine("
")
child.ExpectRegex(`ops\d-host\d-\d-\w\w\w.\w\w\w.host.net login:`)
child.SendLine("root")
child.Expect("Password:")
child.SendLine(pass)
child.ExpectRegex(`\[(\w*)\@(\w*)-host\d-\d-(\w*) \~\]\#`)
child.SendLine(x)
child.ExpectRegex(`\[(\w*)\@(\w*)-host\d-\d-(\w*) \~\]\#`)
child.SendLine("exit")
child.ExpectRegex(`ops\d-host\d-\d-\w\w\w.\w\w\w.host.net login:`)
child.SendLine("\035")
child.Close()
}
I am running a command from a VM to a remote server. This is done with virsh console to the server and gexepect to login, run the command and then logout. My issue comes when trying to exit the console between the hosts. Virsh asks for CTRL +] in order to exit the console. I discovered that the octal for that is \035 and try sending that but nothing happens. I also specify child.Close() which should close the spawned process, which would be the console command, but i still get nothing. The terminal just hangs after the Password is inputted. Everything is executed as expected up until child.SendLine("\035)
. My command is run on the remote server in the background, and logs off back to the OS login screen, but never terminates the virsh console to the remote host.
How would I go about sending CTRL +] through gexpect to exit a virsh console?