-
Notifications
You must be signed in to change notification settings - Fork 3
/
with-password.exp
executable file
·60 lines (47 loc) · 1.03 KB
/
with-password.exp
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
#!/usr/bin/expect
# manpage expect(1) is helpful.
# exp_internal 1 # debug
# Timeout for, e.g., slow connections
set timeout 10
# Though it seems this doesn't work.
unset -nocomplain ::env(SSH_ASKPASS)
set cmd [lrange $argv 0 end]
# expand the list
spawn {*}$cmd
expect {
"assword: " {
set passwd $::env(PPCOMPILE_PASSWORD)
if {"" eq $passwd} {
puts "Empty ppcompile password!"
exit 1
}
send "${passwd}\r"
expect {
# If the password prompt pops up once again
"assword: " {
puts "Incorrect password!"
exit 1
}
}
}
"yes/no" {
send "yes\r"
exp_continue
}
timeout {
puts "timeout"
exit 1
}
# Password is not needed for, e.g., public key authentication
eof {
puts "The end."
}
# fallback
-regex ".*\n" {
exp_continue
}
}
# interact
# catch and propagate the exit code
catch wait result
exit [lindex $result 3]