预计脚本挂起

预计脚本挂起

我正在尝试使用 Expect 在 ovpn 中自动化我的登录过程,但由于一些错误,进展并不顺利。我的脚本:

#!/usr/bin/expect -f
set timeout -1

spawn openvpn --config ./bin/openvpn-lib/cert.ovpn --dev ovpntun0 --up ./bin/openvpn-  lib/update-resolv.conf --down ./bin/openvpn-lib/update-resolv.conf --script-security 2

expect "Enter Auth Username:"

send "myuser\n"

expect "Enter Auth Password:"

send "mypass\n"

interact

当我尝试运行它时,scriptit 报告以下错误:

vpn_expect.sh: line 4: spawn: command not found
couldn't read file "Enter Auth Username:": no such file or directory
vpn_expect.sh: line 8: send: command not found
couldn't read file "Enter Auth Password:": no such file or directory
vpn_expect.sh: line 12: send: command not found
vpn_expect.sh: line 14: interact: command not found
vfbsilva@rohan ~ $ 

答案1

Expect 脚本必须以 Expect 的方式运行

expect <script_name>

将它们作为 shell 脚本运行

sh <script_name>

是问题的原因。

相关内容