Mac OS Script Examples

You can configure the GlobalProtect agent to initiate and run a script for any or all of the following events: before and after establishing the tunnel, and before disconnecting the tunnel. To run the script at a particular event, reference the shell script from a command plist entry for that event. The following topics show examples of scripts that you can run at pre-connect, post-connect and pre-disconnect events:

Example: Terminate All Established SSH Sessions on Mac Endpoints

To force termination of all established SSH sessions before setting up the VPN tunnel, reference the following script from a command plist entry for a pre-vpn-connect event. Similarly, you can re-establish the sessions after establishing the GlobalProtect VPN tunnel by using a script that you reference from the command plist entry for a post-vpn-connect event. This can be useful if you want to force all SSH traffic to traverse the GlobalProtect VPN tunnel.
#!bin/bash 
# Identify all SSH sessions and force kill them 
ps | grep ssh | grep -v grep | awk '{ print $1 }' | xargs
kill -9 

Example: Mount a Network Share on Mac Endpoints

To mount a network share after establishing a VPN connection, reference the following script from a command plist entry for a post-vpn-connect event:
For a script that you can copy and paste, go here.
#!/bin/bash
mkdir $1 
mount -t smbfs //username:password@10.101.2.17/shares/Departments/Engineering/SW_eng/username/folder
$1
sleep 1

Related Documentation