0

I'm trying to use expect to automate my login process in ovpn but due to some mistake it is not going well. My script:

#!/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

WHen I try to run it the scriptit reports the following error:

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 ~ $ 
5
  • 1
    Add interact as the last line of the script. Jun 25, 2020 at 14:17
  • 1
    the 3rd line should be spawn openvpn ... -- otherwise Expect cannot control the process. Jun 25, 2020 at 14:18
  • did update the script but no luck
    – vfbsilva
    Jun 25, 2020 at 15:16
  • 1
    Dont start the script by saying sh vpn_expect.sh or similar. Either make the file executable (chmod +x vpn_expect.sh) then run it with ./vpn_expect.sh, or run it with expect vpn_expect.sh.
    – meuh
    Jun 25, 2020 at 15:31
  • @meuh comment did make the trick
    – vfbsilva
    Jun 25, 2020 at 20:36

1 Answer 1

1

Expect scripts must be run with expect as

expect <script_name>

Running them as shell scripts with

sh <script_name>

Was the cause of the problem.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .