Connect CISCO Anyconnect VPN via bash

前端 未结 5 1644
滥情空心
滥情空心 2020-12-25 08:52

As title says, trying to connect vpn via bash. The following script seemed closest to the answer I\'m looking for:

#!/bin/bash
/opt/cisco/anyconnect/bin/vpn          


        
5条回答
  •  梦毁少年i
    2020-12-25 09:10

    Building on Brayden Hancock's answer, I built a solution that reads the password from the macOS Keychain. As a first step, I added a new password item with the account field set to mycompany-vpn via the Keychain Access app. The first part of the script reads that item back from the keychain and extracts the password using the ruby snippet, the expect script section does the rest.

    #!/usr/bin/env bash
    get_pw () {
        security 2>&1 >/dev/null find-generic-password -ga mycompany-vpn \
        |ruby -e 'print $1 if STDIN.gets =~ /^password: "(.*)"$/'
    }
    
    USER=username
    ADDR=vpn.company.com
    PASSWORD=$(get_pw)
    
    /usr/bin/expect -f - <

提交回复
热议问题