summaryrefslogtreecommitdiffstats
path: root/kernel/networking/libvirt/common/autologin.exp
blob: fd390f0236e2702fbce59d501c3844fff8dd971e (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
#!/usr/bin/expect -f

set login "root"
set password "redhat"

set timeout -1
set guest [lindex $argv 0]
set prompt "$login@.*\](%|#|\\\$) $"

spawn virsh console $guest

#login if needed
expect "Escape character is"
send "\r"
expect { 
         {login:}   { send "$login\r"
                        expect {
                                  {Password:} { send "$password\r" }
                               }
                      }
         -re $prompt    { send "\r"}
       }

expect -re $prompt

#run command
for {set i 1} {$i < $argc} {incr i 1} {
	set cmd [lindex $argv $i]
	send "$cmd\r"
	expect -re $prompt
        sleep 1
}

#capture return code from last command
send "echo RESULT:\$?\r"
expect -re "RESULT:(\\d+)" {
    set result $expect_out(1,string)
}

#logout
send "exit\r"
expect "logout"
exit $result