Linux

期待腳本掛起

  • June 26, 2020

我正在嘗試使用 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

當我嘗試執行它時,腳本會報告以下錯誤:

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 ~ $ 

期望腳本必須以期望執行

expect <script_name>

將它們作為 shell 腳本執行

sh <script_name>

是問題的原因。

引用自:https://unix.stackexchange.com/questions/595037