Quote:
Originally Posted by Bodiless Sleeper
This is the bash script
Code:
#!/bin/bash
cd /home/my_user/Downloads
username="vpnbook"
password="h5bhea6u"
read -sp "Enter Sudo Password: " sudopassword
exec /home/my_user/Downloads/VPN2.exp
And this is the expect script
Code:
#!/usr/bin/expect
spawn sudo openvpn vpnbook-de4-tcp443.ovpn
expect "password for my_user: "
send "$sudopassword\r"
expect "Enter Auth Username: "
send "$username\r"
expect "Enter Auth Password: "
send "$password\r"
expect "$ "
EOF
|
I don't think that "username" and "password" are being passed to the environment seen by Expect.
You ought to be able to pass that information to the expect script on the command line as
Code:
exec /home/my_user/Downloads/VPN2.exp $username $password
and retrieve these within the Expect script with something like
Code:
set username [lindex $arg0]
set password [lindex $arg1]
You'll need to include the "-f" switch on the shebang line for this to work, though. And... the big caveat with this is that "username" and "password" would be visible to anyone who knows to execute "ps" while your Expect script is running. Also, if they were defined in your environment, you could see them with the right "ps" switch anyway.
You could also put the login information (say: "username/password") into a hidden file with permissions that hide it from everyone but you (and root) and open that file in the Expect script. That's a little more involved and my Expect is pretty rusty but you could do something like:
Code:
set pwfile ".vpninfo.dat"
set pw [open ./$pwfile r]
set pwrecord [split [read $pw] "\n"]
if {[string length $pwrecord] > 0} {
# Split "pwrecord" to get sitename, username, password, whatever
# How you do this depends on how you format the user/pw record(s)
# If you have multiple records in the file you'll need a foreach{}
# loop.
}
# Spawn the VPN connect command using the parsed information...
This is approximately what you'd need. (Hey... I
did say my Expect was rusty. And my textbooks are in storage for the time being.) I suspect you can figure out the rest.
Have fun...