blob: 85c5ef1abdaddda3880d9f742d847921be3e3b00 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
#!/usr/bin/expect
if { $argc != 1 } {
send_user "Usage: $argv0 guestname \n";
exit 1;
}
set guestname [lindex $argv 0]
set prompt "\n(.*?(%|#|\\\$)) $"
set user "root"
set pass "rhts"
set i 0
log_user 0
spawn virsh console $guestname
expect {
-exact "login: " { send "$user\n"; exp_continue; }
-re "(P|p)assword:" { send "$pass\n"; exp_continue; }
-re $prompt {
set thelist [split $expect_out(0,string) "\n" ]
set theprompt [string trim [lindex $thelist end]]
send "hostname\n";
}
timeout {
if { $i < 2 } {
send "\n"
incr i
exp_continue
} else {
send_user "didn't get prompt in $timeout seconds \n";
exit 1;
}
}
eof {
send_user "Unexpected EOF ..\n";
exit 1;
}
}
expect {
-re $prompt {
set idx [string first "$theprompt" $expect_out(1,string)]
set host [string range $expect_out(1,string) 0 [expr $idx - 1]]
send_user "${host}"
}
timeout {
send_user "timeout waiting for the prompt\n"
}
eof {
send_user "eof waiting for the prompt\n"
}
}
exit 0
|