summaryrefslogtreecommitdiffstats
path: root/distribution/virt/import/wait4login
blob: 349d21bd8744ba54ddf4c3067456dcb4178226ea (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
#!/usr/bin/expect

if { $argc != 1 && $argc != 2 } {
	send_user "Usage: $argv0 guestname <timeout>\n";
	send_user "timeout is optional. \n"
	exit 1;
}
set timeout   -1
set guestname [lindex $argv 0]
set prompt    "(%|#|\\\$) $"

if { $argc == 2 } {
	if { ![string is integer [lindex $argv 1]] } {
		send_user "Timeout value must be an integer.\n";
		exit 1;
	}
	set timeout [lindex $argv 1]
}

# spawn whatever the guest is configured with
if { [catch {exec isfileconsole $guestname} errStr] } {
	spawn virsh console $guestname
	sleep 1
	send "\r\n"
	sleep 1
	send "\r\n"
} else {
	if { [ catch { set console_file [exec getconsolefile $guestname] } ] } {
		send_user "error with set console_file \[getconsolefile $guestname\] \n"
		exit 1;
	}
	spawn tail -f $console_file
}
expect {
	-exact "login: " { exit 0; }
        timeout {  
		send_user "didn't get prompt in $timeout seconds \n";
		exit 1;
	}
	eof {
		send_user "Unexpected EOF ..\n";
		exit 1;
	}
}

#should never come here ...
exit 1;