Skip to content

Instantly share code, notes, and snippets.

@shalk
Created October 16, 2013 06:51
Show Gist options
  • Save shalk/7003628 to your computer and use it in GitHub Desktop.
Save shalk/7003628 to your computer and use it in GitHub Desktop.
virsh console with expect
#!/bin/bash
expect -c "
set timeout 10
spawn virsh console cvm1
expect {
\"Escape character\" {send \"\r\r\" ; exp_continue}
\"Escape character\" {send \"\r\r\" ; exp_continue}
\"login:\" {send \"root\r\"; exp_continue}
\"Password:\" {send \"111111\r\";}
}
expect \"~ #\"
send \"echo 123\r\"
expect \"~ #\"
send \"date\r\"
send \"exit\r\"
expect \"login:\"
send \"\"
expect eof
"
@danktec
Copy link

danktec commented Aug 16, 2016

Nice work! Thank you

@dynacade
Copy link

dynacade commented Jun 5, 2018

I use this script all the time!

Thanks!

Anyway to make it wait to see a "Login:" during a reboot? This script assumes the VM is already up I am trying to find a way to execute as soon as the reboot is finished. Any ideas?

@mengqi1984
Copy link

This is good.

@cutty853
Copy link

excellent !

@eric-create
Copy link

Thank you!

@frenchy35
Copy link

Hi, I’ve tryed to use it on centos 7, it work 1 time on 2 try, any explanation !? Thanks in advance

__
Philipp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment