Help with script to set routes for VPN split tunnel

Hi. I know virtually nothing about scripting and need some help. I used to have a script to enable split-tunneling when connected to a VPN. It worked great until I got this new machine running Sonoma. Now it won’t run even though the commands work fine when run as Sudo in Terminal.

This is the script text:

$ cat vpn.sh
#!/bin/bash

if [[ $EUID -ne 0 ]]; then
echo “Run this as root”
exit 1
fi

route -nv add -net 192.168.2.0/24 -interface ppp0
route -nv add -net 192.168.3.0/24 -interface ppp0
route change default 192.168.1.1

When I try to recreate the script I get an error about syntax. Since I know nothing about scripting, I have no way to troubleshoot.

I’m sure someone is going to ask why I want to do this when I could just enable split tunneling in the VPN settings. Well, that’s easy. If split tunneling is enabled, I can’t connect to my computer on the other end. That’s just how our IT department set things up. But leaving split tunneling disabled and adding the routes via terminal works great, except I have to do it every time I connect.

It used to be that I had the script run on startup and that was enough. Now I think I may need to have it run every time I connect the VPN.

If there’s a better way to make these routes persistent, I’m all eyes (on the screen to read the responses).

Can anyone help me with this?

This site is mostly dedicated to AppleScript (although it’s not exactly clear from its name as I realize now.) You’re using shell script.

It’s still quite possible that someone here can help you with your particular script. Still, you may want to post your question on stackoverflow.com. (Also, make sure to include the exact “error about syntax” you get.)

Thanks for the response.

It doesn’t matter to me how it works, so long as it does. Can it be done with AppleScript instead?

I personally know nothing about VPN. Your shell scripts can be run from AppleScript but that’s not the point as you need to fix those shell scripts in the first place.

I assume you’re running a specific VPN app which may have its own AppleScript dictionary - but we don’t know what app is that and, once again, I would know nothing about it anyway.

Like I mentioned, try to post your question on stackoverflow.com. It appears to me you’ll have much better luck there. There are much broader range of developers on that website who can help you with VPN questions.