Hi,
I'm very new to TCL/Expect and I am trying to use expect to automate
booting a PXE linux distro over serial console, grab the DHCP discover
IP and execute a ssh login. So far I have everything working except
for parsing one of the following lines and doing something like the
result of cut -f -d' ' in a bash script. Can someone help me to better
understand expect_out functions in this scenario?
Kernel boot messages over serial console:
..
IP-Config: Got DHCP answer from 10.60.132.162, my address is
10.2.2.251
pcieport 0000:00:1c.4: wake-up capability enabled by ACPI
IP-Config: Complete:
device=eth1, addr=10.2.2.251, mask=255.255.255.0, gw=10.2.2.1,
host=1.2.3.5, domain=
foo.com, nis-domain=
foo.com,
bootserver=1.2.3.4, rootserver=1.2.3.4, rootpath=
..
#!/usr/bin/expect -f
set timeout 1200
set send_human {.1 .2 1 .02 2} #so we dont miss keystrokes over the
serial console connection.
spawn ##POWER CYCLE SWITCHED PDU HERE
sleep 30
spawn telnet [lindex $argv 0] ##TELNET CONSOLE HERE
expect "boot:"
send -h "trinity-3.4"
send "\r\n"
expect "Starting sshd"
expect "OK"
sleep 6
spawn ssh -l root [lindex $argv 0] <<Currently it breaks here
without resolving IP from DHCPDiscover
expect {
"(yes/no)?" {send "yes\n"; exp_continue}
"assword:" {send "trk\n"}
}
expect "trk"
send -h "winpass\n"
expect "\[1\]\:"
send -h "1\n"
expect "Select"
send -h "4\n"
expect "trk"
send -h "winpass\n"
expect "\[1\]\:"
send -h "1\n"
expect "Select"
send -h "1\n"
send -h "reboot\n"
send_user "Password reset request completed successfully."
eof