Skip to content

Instantly share code, notes, and snippets.

@sming
Last active January 2, 2023 18:34
Show Gist options
  • Save sming/0c56fb7a54a68d502aded2b71e501bba to your computer and use it in GitHub Desktop.
Save sming/0c56fb7a54a68d502aded2b71e501bba to your computer and use it in GitHub Desktop.
#!/bin/bash
# Props to https://gist.github.com/kaleksandrov/3cfee92845a403da995e7e44ba771183 from whom I took the code inside
# the conditional.
THIS_SCRIPT_INVOCATION=$0
# The return status of this function will be 0 if globalprotect is running, 1 if not running because grep returns 0
# if it finds a match and 1 if not.
# We basically grep for globalprotect but exclude all the matches we don't want
ps-grep () {
ps auwwwwx | grep -i globalprotect | grep -v "$THIS_SCRIPT_INVOCATION" | grep -v 'grep ' | grep -v "%CPU" > /dev/null
}
ps-grep
IS_RUNNING=$?
if [ "$IS_RUNNING" -eq "0" ]
then
echo "Stopping GlobalProtect..."
launchctl remove com.paloaltonetworks.gp.pangps
launchctl remove com.paloaltonetworks.gp.pangpa
echo "Done!"
else
echo "Starting GlobalProtect..."
launchctl load /Library/LaunchAgents/com.paloaltonetworks.gp.pangpa.plist
launchctl load /Library/LaunchAgents/com.paloaltonetworks.gp.pangps.plist
echo "Done!"
fi
@vurtomatic
Copy link

vurtomatic commented Apr 9, 2022

Hi there, I've never used a .sh before.

When I run this script in Terminal, I get this error:

line 13: `ps-grep': not a valid identifier

@ndutyme
Copy link

ndutyme commented Apr 19, 2022

I don't think this command works for some GlobalProtect clients or OS versions. Running either this script, or either commands individually as root on my macOS 12.2.1 system does not stop or start the GlobalProtect client and it also does not break my GlobalProtect clients VPN connection to our Firewall. Maybe something changed either with the GP client, it's configuration (could ours be configured to not allow this), or something new in the macOS 12.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment