title: Bash Script for automated OpenVPN logon
body: <p>I am very new to bash scripting, so I apologize in advance for being vague. I have a varied number of OpenVPN configuration profiles I need to connect too on a daily basis, and would like to make this a little easier by introducing automation. </p>
  
  <p>So I am able to get to the authorization part of the process and that's where I get stuck: </p>
  
  <pre><code>  Your IP is xx.xx.xx.xx
  Mon Oct 13 09:57:14 2014 OpenVPN 2.2.1 i486-linux-gnu [SSL] [LZO2] [EPOLL] [PKCS11] [eurephia] [MH] [PF_INET6] [IPv6 payload 20110424-2 (2.2RC2)] built on Jun 19 2013
  Enter Auth Username:
  </code></pre>
  
  <p>I would like to know how I can use bash to automatically log on using my username and password. So the script would populate and confirm the 2 authorization fields. </p>
  
  <p>Enter Auth Username: username</p>
  
  <p>Enter Auth Password: password</p>
  
  <p>Then once populated and confirmed, I will be connected to the VPN.</p>
  
  <p>I appreciate any help, and please let me know if more information is required.</p>
  
  <p>My current script I am working with is this:</p>
  
  <pre><code>#!/bin/sh
  expect_path="$(which expect)"
  "$expect_path" "$0" "$@"
  
  #!/bin/usr/expect -f
  
  spawn sudo openvpn /root/Desktop/my.conf #Path to Openvpn config file (.ovpn)
  expect -r "\[sudo\] .*\: " {
      send "my_ownpassword\n"
  }
  expect "Enter Auth Username:" {
      send "my_user\n"
  }
  expect "Enter Auth Password:" {
      send "my_vpnpassword\n"
  }
  interact
  </code></pre>
  
  <p>Current error I am getting:</p>
  
  <pre><code>can't read "(which expect)": no such variable
      while executing
  "expect_path="$(which expect)""
      (file "./vpn.sh" line 2)
  ./vpn.sh: 7: ./vpn.sh: spawn: not found
  expect: invalid option -- 'r'
  usage: expect [-div] [-c cmds] [[-f] cmdfile] [args]
  ./vpn.sh: 9: ./vpn.sh: send: not found
  ./vpn.sh: 10: ./vpn.sh: Syntax error: "}" unexpected
  </code></pre>