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.
So I am able to get to the authorization part of the process and that's where I get stuck:
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:
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.
Enter Auth Username: username
Enter Auth Password: password
Then once populated and confirmed, I will be connected to the VPN.
I appreciate any help, and please let me know if more information is required.
My current script I am working with is this:
#!/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
Current error I am getting:
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