问题描述
我有一个这样的期望脚本
I have an expect script like this
#!/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连接,但是它无法正常工作,因为子进程产生的子进程被期望杀死.如您所知,期望在完成之前发送SIGHUP信号,我试图解决它,但是即使我放了-ignore HUP标志,它也正在杀死底层进程,我想结束脚本,但是底层openconnect在后台运行生存.
This simple script provides user and password to openconnect to make a new VPN connection in background, but it wont work because the children spawned processes are killed by expect. As you may know, expect will send SIGHUP signal before finish, I was trying to workaround it but even when I put the -ignore HUP flag, it is killing the underlying process, I would like to end my script but the underlying openconnect in background survive.
您知道这里缺少什么吗?
Do you know what is lacking here?
考虑到openconnect -b将自己产生其他PID.
Take into account that openconnect -b will spawn other PID by its own.
推荐答案
为此花了太多时间后,我通过添加
After spending too much time on this, I solved it by adding
expect -timeout -1 -ex "Client killed"
并使用&
./vpn.exp &
这篇关于TCL期望杀死孩子进程的孩子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!