#!/usr/bin/expect -f # # Usage: # vpn-auto.exp # # 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 " 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 } -re "Login failed." { send_user "Detected: Login failed. Exiting.\n" close wait exit 1 } eof }