Can this be automated? Plex Media Server with Mullvad


Just a quick question, I want to automate my Plex/Mullvad setup to work with split tunnelling after a reboot.

Currently, following a reboot, i need to run a few commands to get it up and running, these are:

  1. systemctl status plexmediaserver to get the PID for Plex (or ps ax | grep 'plex' if you're that way inclined)

  2. mullvad split-tunnel pid add <pid> to add Plex PID to split tunnelling

  3. nft -f plex.rules to allow listening on the Plex port

plex.rule contents:

table inet excludeTraffic {
  chain allowIncoming {
    type filter hook input priority -100; policy accept;
    tcp dport 32400 ct mark set 0x00000f41 meta mark set 0x6d6f6c65;
  chain allowOutgoing {
    type route hook output priority -100; policy accept;
    tcp sport 32400 ct mark set 0x00000f41 meta mark set 0x6d6f6c65;

Anyone know how it may be possible to automate the finding of the PID and then add it into a script with the rest of the needed commands?

I am researching it myself, just thought I'd ask.

Thanks in advance


pgrep plexmediaserver

return plex's pid? If it does then you can do this,
In a script .sh file,

mullvad split-tunnel pid add $(pgrep plexmediaserver)
nft -f plex.rules

then make it executable with

chmod 755

and bind it to a shortcut.


You could create a systemd startup service.


Hi Kiss-my-axe and thanks for your input.

Sadly pgrep plexmediaserver returns nothing

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.