summaryrefslogtreecommitdiffstats
path: root/distribution/virt/import/guest1cmd
blob: c22c0dcd1e8826cc1d78c92a20a6eaf01abb2433 (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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/expect

if { $argc != 2 } {
	send_user "Usage: $argv0 guestname cmd\n";
	exit 1;
}
set guestname [lindex $argv 0]
set cmd       [lindex $argv 1]
set prompt    "\n(.*?(%|#|\\\$)) $"
set user "root"
set pass "rhts"
set timeout 30
set i 0
log_user 0
#exp_internal 1

spawn virsh console $guestname
sleep 3
send "\n"
send "\n"
expect { 
	-exact "login: " { send "$user\n"; exp_continue; }
	-re "(P|p)assword:" { send "$pass\n"; sleep 10; send  }
	timeout { send  }
	eof { }
}
spawn virsh console $guestname
send "\n"
send "\n"
sleep 5
expect {
	-re $prompt { 
		set thelist [split $expect_out(0,string) "\n" ]
		set theprompt [string trim [lindex $thelist end]]
		send "$cmd\n"; send ;
	}
		 		
        timeout {  
		if { $i < 3 } {
			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;
	}
}

spawn virsh console $guestname
expect {
	-re $prompt { 
		set idx [string first "$theprompt" $expect_out(1,string)]
		set out [string range $expect_out(1,string) 0 [expr $idx - 1]]
		send_user "${out}"
	}
	timeout {
		send_user "timeout waiting for the prompt\n"
	}
	eof {
		send_user "eof waiting for the prompt\n"
	}
}

exit 0