EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
后台执行的方法:disconnect #!/usr/bin/expect spawn openvpn --config ./test.ovpn
3 k+ C: {$ P) R$ D+ z4 J% dexpect "*Username:"
8 R1 y" U( e1 G0 J) dsend "root\r" expect "*Password:"
8 a6 o# R7 r# l) Bsend "passwd\r" if [fork]!=0 exit
( o" G$ X& V$ s5 ~- y" Z7 ddisconnect ! T# E! D0 ~) k* R- p
传递参数的方法:set name [lindex $argv 0] #!/usr/bin/expect
; D# C1 e. W+ b& Q9 A& Q$ l" a& Q/ K7 R/ ^
if { $argc != 2 && $argc != 1 } {
7 ~; a& k1 u, G# H1 Z send_user "Usage:auth username \[password\]\n"8 b1 v, e5 Z- r/ X# `- `- ]: n% T
send_user "\tthe default password equals 0000\n"
; }' C6 Y4 S6 @3 B- U exit8 L* \0 s2 ^8 @6 v8 d+ k; s* k1 G, A) d* Q
}( u+ }; k$ p; S7 \; t: p v
' `4 S7 y% b/ ]' ]set name [lindex $argv 0]( O6 ~" w( {* G" ?: J A
if { $argc == 2 } {
' J- c8 W' a: p/ z% ? set pass [lindex $argv 1]
8 W* e$ t) _, p5 l/ Z% Z, w- O: F} else { set pass "0000" }
: S4 R6 i3 S; d- n2 P q; H, |" S4 V: F3 s1 Q; R
spawn xrgsu
1 B/ Z; Y: q6 u7 V/ r
7 h; _% z* q' n6 L# expect 开始
6 F) w9 c0 x5 kexpect "*user*" { send ${name}\r }
/ M; {; M" e6 q+ p! T/ q! aexpect "*password:" { send ${pass}\r }7 C! e( Z' x; D0 e+ w6 l
expect "*DHCP*" { send "\r" }
1 b/ d# s2 b4 t/ X' kexpect "*auth*" { send "\r" }
3 i' M& r# r! z* Q4 ~$ Q) M: E1 ^2 R8 u$ K
interact _/ A4 e4 ]) f3 e1 c! \. J/ a
#EOF - B2 r6 {9 `. v" l2 y7 e
|