# You might find these Linux scripts useful

**URL:** <https://forums.plex.tv/t/you-might-find-these-linux-scripts-useful/926415>\
**Category:** Apps & Creations\
**Tags:** server-linux\
**Created:** [July 19, 2025, 9:10pm UTC](https://forums.plex.tv/t/you-might-find-these-linux-scripts-useful/926415 "2025-07-19T21:10:07Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![lxtwin](https://avatars.discourse-cdn.com/v4/letter/l/9fc348/32.png) [@lxtwin](https://forums.plex.tv/u/lxtwin)\
**Post date:** [July 19, 2025, 9:10pm UTC](https://forums.plex.tv/t/you-might-find-these-linux-scripts-useful/926415/1 "2025-07-19T21:10:07Z")

</div>

I find that plexmediaserver could do with an update script and a watcher script. I use these on mint linux.

The update script - /root/bin/UpdatePlex.sh

```auto
#!/bin/bash

# Requires: jq, curl
# Install jq if needed: sudo apt install jq

# Get the current installed version
INSTALLED=$(dpkg -s plexmediaserver | grep '^Version' | awk '{print $2}')

# Get latest version info from Plex
LATEST=$(curl -s https://plex.tv/api/downloads/5.json | jq -r '.computer.Linux.version')

echo "Installed version: $INSTALLED"
echo "Latest version: $LATEST"

if ["$INSTALLED" != "$LATEST"]; then
    echo "Update available. Downloading..."
    URL=$(curl -s https://plex.tv/api/downloads/5.json | jq -r '.computer.Linux.releases[] | select(.build=="linux-x86_64" and .distro=="debian") | .url')
    curl -L -o plex.deb "$URL"
    sudo dpkg -i plex.deb
    rm plex.deb
    echo "Update complete!"
else
    echo "Plex is already up to date."
fi

```

My timer that checks to see if plex is running, if not will restart it.

/usr/local/bin/check-plex.sh

```auto
#!/bin/bash

# Check if Plex is running
if ! systemctl is-active --quiet plexmediaserver; then
    echo "$(date): Plex Media Server is not running. Attempting restart..." >> /var/log/plex-monitor.log
    systemctl restart plexmediaserver
else
    echo "$(date): Plex Media Server is running fine." >> /var/log/plex-monitor.log
fi

```

Work on the service - /etc/systemd/system/plex-monitor.service

```auto
[Unit]
Description=Monitor and restart Plex Media Server if it's not running
After=network.target

[Service]
Type=oneshot
ExecStart=/usr/local/bin/check-plex.sh

```

Create the timer - /etc/systemd/system/plex-monitor.timer

```auto
[Unit]
Description=Run Plex Monitor Script Every 5 Minutes

[Timer]
OnBootSec=5min
OnUnitActiveSec=5min
Unit=plex-monitor.service

[Install]
WantedBy=timers.target

```

Enable and start the timer.

```auto
systemctl daemon-reexec
systemctl enable --now plex-monitor.timer

root@Linux-Plex-Server:~/bin
└─ $ ▶ $ systemctl list-timers
NEXT LEFT LAST PASSED UNIT ACTIVATES                     
Sat 2025-07-19 22:12:01 BST 2min 19s Sat 2025-07-19 22:07:01 BST 2min 40s ago plex-monitor.timer plex-monitor.service
Sat 2025-07-19 22:25:55 BST 16min Sat 2025-07-19 21:39:44 BST 29min ago fwupd-refresh.timer fwupd-refresh.service

root@Linux-Plex-Server:~/bin
└─ $ ▶ $ cat /var/log/plex-monitor.log
Sat 19 Jul 21:55:03 BST 2025: Plex Media Server is running fine.
Sat 19 Jul 21:56:58 BST 2025: Plex Media Server is running fine.
Sat 19 Jul 22:01:59 BST 2025: Plex Media Server is running fine.
Sat 19 Jul 22:07:01 BST 2025: Plex Media Server is running fine.

```

---

<div class="post-metadata">

**Author:** ![ChuckPa](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/chuckpa/32/79710_2.png) [@ChuckPa](https://forums.plex.tv/u/ChuckPa)\
**Post date:** [July 19, 2025, 9:53pm UTC](https://forums.plex.tv/t/you-might-find-these-linux-scripts-useful/926415/2 "2025-07-19T21:53:27Z")

</div>

> [@lxtwin](#):
>
> ```auto
> #!/bin/bash
> 
> # Check if Plex is running
> if ! systemctl is-active --quiet plexmediaserver; then
> echo "$(date): Plex Media Server is not running. Attempting restart..." >> /var/log/plex-monitor.log
> systemctl restart plexmediaserver
> else
> echo "$(date): Plex Media Server is running fine." >> /var/log/plex-monitor.log
> fi
> 
> ```

You might want to add the `is-enabled` qualifier for those who don’t want PMS to forcibly restart every time the script runs.

You should also consider DBRepair running and optimizing the DB.  
If PMS restarts in the middle of this – DB Corruption

* * *

If you enable the Repository, `apt update && apt -y ugprade` will do the upgrade when it’s available (Public)

---

<div class="post-metadata">

**Author:** ![lxtwin](https://avatars.discourse-cdn.com/v4/letter/l/9fc348/32.png) [@lxtwin](https://forums.plex.tv/u/lxtwin)\
**Post date:** [July 20, 2025, 7:11pm UTC](https://forums.plex.tv/t/you-might-find-these-linux-scripts-useful/926415/3 "2025-07-20T19:11:05Z")

</div>

Thanks, I have cloned the repo.

---

<div class="post-metadata">

**Author:** ![ChuckPa](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/chuckpa/32/79710_2.png) [@ChuckPa](https://forums.plex.tv/u/ChuckPa)\
**Post date:** [July 20, 2025, 9:13pm UTC](https://forums.plex.tv/t/you-might-find-these-linux-scripts-useful/926415/4 "2025-07-20T21:13:24Z")

</div>

Cloned the repo? My repo?

Don’t clone it. It wasn’t my intent to clone DBRepair

My suggestion was to enable the Plex repository

`/etc/apt/sources.list.d/plexmediaserver.list`

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/plex/original/3X/2/a/2acb9765406f63293d357b4ec509ec39aa28f2ad.png) [@system](https://forums.plex.tv/u/system)\
**Post date:** [October 18, 2025, 9:14pm UTC](https://forums.plex.tv/t/you-might-find-these-linux-scripts-useful/926415/5 "2025-10-18T21:14:04Z")

</div>

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