feisky

云计算、虚拟化与Linux技术笔记
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

如何让expect进程后台执行

Posted on 2011-11-17 13:17  feisky  阅读(1790)  评论(0编辑  收藏  举报

后台执行的方法: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

无觅相关文章插件,快速提升流量