This commit is contained in:
Zsolt Alföldi
2025-07-22 16:07:01 +02:00
commit bf26c46b48
5 changed files with 58 additions and 0 deletions

43
run.exp Executable file
View File

@@ -0,0 +1,43 @@
#!/usr/bin/expect -f
#
# Usage:
# vpn-auto.exp <connection-name> <vpn-user> <vpn-pass> <otp-secret>
#
# Example:
# ./vpn-auto.exp PEM_PASS VPN_USER VPN_PASS MS_AUTH_OTP
# ./vpn-auto.exp pass1234 zsolt.alfoldi@nokia.com 1234pass 987456
# never timeout
set timeout -1
# pull args off the command line
if { $argc != 4 } {
puts stderr "Usage: $argv0 <vpn-name> <user> <pass> <otp-secret>"
exit 1
}
lassign $argv vpn_pem_pass vpn_user vpn_pass otp
# start the connection
spawn nmcli connection up Nokia --ask
# watch for the prompts and supply answers
expect {
-re "Enter PEM pass phrase" {
send "$vpn_pem_pass\r"
exp_continue
}
-re "Username:" {
send "$vpn_user\r"
exp_continue
}
-re "PASSCODE:" {
send "$vpn_pass\r"
exp_continue
}
-re "Response:" {
send "$otp\r"
exp_continue
}
eof
}