【发布时间】:2018-01-16 15:06:47
【问题描述】:
我有一个像这样的期望脚本
#!/usr/bin/expect -f
set timeout 30
log_user 0
set PASSWORD $::env(PASSWORD)
set USERNAME $::env(USERNAME)
set TOKEN $::env(TOKEN)
puts stderr "Generating OTP"
spawn oathtool --totp $TOKEN
expect -re \\d+
set otp $expect_out(0,string)
puts stderr "Connecting to VPN server"
spawn -ignore HUP env openconnect -b https://vpn
expect "GROUP:"
send "Tech\n"
expect "Username:"
send "$USERNAME\n"
expect "Password:"
send "$PASSWORD\n"
expect "Password:"
send "$otp\n"
expect EOF
这个简单的脚本提供了 openconnect 的用户名和密码以在后台建立一个新的 VPN 连接,但它不会工作,因为子进程被期望杀死。如您所知,expect 将在完成之前发送 SIGHUP 信号,我试图解决它,但即使我放置了 -ignore HUP 标志,它也会杀死底层进程,我想结束我的脚本,但底层的 openconnect 在后台活下来。
你知道这里缺少什么吗?
考虑到 openconnect -b 将自己生成其他 PID。
【问题讨论】:
-
这还不够清楚 - 你能详细说明一下吗:“但它不会工作,因为子进程被期望杀死,即使我放了 -ignore HUP 标志,它也会杀死这个底层进程"
-
我用其他方法解决了这个问题,但我现在添加了更多细节,这个问题看起来更好吗?
标签: linux tcl expect openconnect