EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
后台执行的方法:disconnect #!/usr/bin/expect spawn openvpn --config ./test.ovpn v! w& B5 i; n+ j! |/ }6 b
expect "*Username:"
& O1 T! y7 q0 q& t9 G5 psend "root\r" expect "*Password:"! l9 \1 Z5 ^ A5 f- Z9 y) @
send "passwd\r" if [fork]!=0 exit
{% c0 n' U3 l4 V; ?" \disconnect
2 y: t6 x+ n9 u4 T3 ^: E+ F传递参数的方法:set name [lindex $argv 0] #!/usr/bin/expect
. v! L( o; i) M2 [3 m5 X; i3 Y7 c' E; N) r. T
if { $argc != 2 && $argc != 1 } {
; k3 q0 Q0 f! j send_user "Usage:auth username \[password\]\n"
. P) ~3 E' W) R5 ? send_user "\tthe default password equals 0000\n"
. W% p; Y) c7 K4 v exit
! E' v: Y- Z) j) o( e8 c: X6 J}* y- T; T; J8 ?0 S" j
: |1 A: G5 d% m
set name [lindex $argv 0]5 f8 V% j5 ?6 X' w) M" J7 Q: ^
if { $argc == 2 } {
) c& z- ~! g# h, B4 d7 w set pass [lindex $argv 1]
3 l+ M f( _5 V4 |} else { set pass "0000" }; B; n. E5 j+ g8 U, t
' z E( X9 Q4 a
spawn xrgsu, M/ x) U2 ^1 `7 t9 G+ b% h
+ @2 U$ c( Y, s$ B+ _# expect 开始
+ x0 H$ c! @* mexpect "*user*" { send ${name}\r }9 {7 h6 F' O% N4 V2 o7 V! C$ K/ G. ]
expect "*password:" { send ${pass}\r }
8 l: d/ I8 F# P, k8 D! T" lexpect "*DHCP*" { send "\r" }2 x# l+ ]5 J8 j* W) l2 I( y
expect "*auth*" { send "\r" }
3 C$ `. K. M. `7 |
. j7 D1 J( M5 Dinteract
- a- T' u+ k% ~) I/ u& J; ]9 A#EOF
! V" n, P2 w7 m$ }! F& b( h |