Thursday, April 25, 2024
2
rated 0 times [  2] [ 0]  / answers: 1 / hits: 3522  / 1 Year ago, wed, april 5, 2023, 7:29:01

I am trying to automate my vpn using a shell scipt



What I want is to get a webpage (curl) and parse it for password.
If I write a normal script looks something like:



var=$(curl -i http://www.vpnbook.com/freevpn | grep "Password: <strong>*")
echo ${var:26:8}


This outputs a password.



Now, I want to parse this via expect, store it, and then run the openvpn command:



spawn sudo openvpn --config vpnbook-euro2-tcp443.ovpn
expect "Enter Auth Username:"
send "vpnbook"
expect "Enter Password: "
send $pass


I am unable to set this pass variable properly.



Any Ideas?


More From » command-line

 Answers
7

You can use the environment to store the value, and use expect's env array to retrieve it:



var=$(curl -i http://www.vpnbook.com/freevpn | grep "Password: <strong>*")
export passwd=${var:26:8}
expect -c '
spawn sudo openvpn --config vpnbook-euro2-tcp443.ovpn
expect "Enter Auth Username:"
send "vpnbook"
expect "Enter Password: "
send $env(passwd)
interact
'

[#28686] Friday, April 7, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
truwom

Total Points: 101
Total Questions: 99
Total Answers: 100

Location: Ivory Coast
Member since Tue, Sep 15, 2020
4 Years ago
;