简体   繁体   English

防止期望在 EOF 上退出

[英]prevent expect from exiting on EOF

I have an expect script that connects to a vpn using openconnect.我有一个使用 openconnect 连接到 vpn 的期望脚本。 The script works perfectly, except that I don't know how to keep openconnect alive once the password has been provided and expect has reached the EOF.该脚本完美运行,除了我不知道一旦提供密码并且期望达到 EOF 后如何保持 openconnect 活动。 I think I need to fork the process, but I need it to keep the password somehow.我想我需要分叉这个过程,但我需要它以某种方式保留密码。 Here is my script这是我的脚本

#!/usr/bin/expect -f

spawn ./openconnect
expect "sudo"
send "sudo_password\r"
expect "password:"
send "vpn_password\r"
expect /Connected\stun1\sas/ #expect connected tun1 as some ip

and openconnect并打开连接

#!/usr/bin/env bash

sudo -k
sudo -S openconnect --juniper --user username --csd-wrapper ~/juniper-vpn-py/tnc vpn_server

The output gets to connected tun1 as some ip as expected, but then expect closes and so does the process is spawned.输出按预期作为某个 ip 连接到 tun1,但随后 expect 关闭,进程也随之产生。

You have to wait for the spawned process to finish before exiting the Expect scirpt or the spawned process may be killed prematurely.在退出 Expect 脚本之前,您必须等待生成的进程完成,否则生成的进程可能会过早终止。 Try like this:像这样尝试:

expect "Connected tun1 as"
expect -timeout -1 eof     ; # change the timeout value as needed

or或者

expect "Connected tun1 as"
interact

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM