后台执行的方法:disconnect
#!/usr/bin/expect
spawn openvpn --config ./test.ovpn
expect "*Username:"
send "root\r"
expect "*Password:"
send "passwd\r"
if [fork]!=0 exit
disconnect
传递参数的方法:set name [lindex $argv 0]
#!/usr/bin/expect
if { $argc != 2 && $argc != 1 } {
send_user "Usage:auth username \[password\]\n"
send_user "\tthe default password equals 0000\n"
exit
}
set name [lindex $argv 0]
if { $argc == 2 } {
set pass [lindex $argv 1]
} else { set pass "0000" }
spawn xrgsu
# expect 开始
expect "*user*" { send ${name}\r }
expect "*password:" { send ${pass}\r }
expect "*DHCP*" { send "\r" }
expect "*auth*" { send "\r" }
interact
#EOF