EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
后台执行的方法:disconnect #!/usr/bin/expect spawn openvpn --config ./test.ovpn & h& q3 S( }$ ^# w6 |
expect "*Username:"
" X3 z% y4 V! Esend "root\r" expect "*Password:"
" w9 i! x- a+ r+ y* Psend "passwd\r" if [fork]!=0 exit1 [, ?- q; W5 O3 W0 A
disconnect
+ ^" d6 U4 F; @+ x传递参数的方法:set name [lindex $argv 0] #!/usr/bin/expect; o5 Q( F+ G3 O2 C6 t
5 ]- ?' y5 F+ f
if { $argc != 2 && $argc != 1 } {
& v+ j+ n1 a8 { send_user "Usage:auth username \[password\]\n"+ B* d" q, ]" D' i2 o
send_user "\tthe default password equals 0000\n"
5 q" G8 d" S. k& {1 s exit
7 l. I. h' }& W3 Q2 p. T}
/ K$ x4 \: H K2 g* Q* P, t; L, g6 r1 r3 Y
set name [lindex $argv 0]
' S3 @; N+ Z8 B5 h" x3 m" b7 Gif { $argc == 2 } {2 {+ F# X0 y. L. c4 ]0 m
set pass [lindex $argv 1]
5 }- v% W9 Q: w& y} else { set pass "0000" }
( m3 A- ^/ W6 j6 L. V5 S, T1 n
' \& O' M5 ]- t# I8 o Tspawn xrgsu
. ~0 J8 c2 d5 a& A( U, ~+ }4 G
; N" X/ E( T% [9 i% @# expect 开始
% m4 m$ \9 @5 ^( n$ d* A+ S2 l/ Oexpect "*user*" { send ${name}\r }
/ Y1 g6 ]4 P9 {/ eexpect "*password:" { send ${pass}\r } M8 B! q! r+ y c
expect "*DHCP*" { send "\r" }
2 |- e$ C) n" Hexpect "*auth*" { send "\r" }
+ N7 ^! R: _0 S0 p( P8 k
" T9 l& J; s! b6 o* c. r pinteract
. p+ N+ T i- L: `#EOF
t, X; O. J- R, Z/ g; a4 T% e |