Created
May 26, 2025 12:47
-
-
Save xobust/d4b64b02e31ca9d26847fa9a9ec20348 to your computer and use it in GitHub Desktop.
Wakes up a sleeping disk when a user logs onto plex (requires sh package)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# pip install sh | |
from sh import tail | |
from datetime import datetime | |
import re | |
plexLog = "/Users/USERNAME/Library/Logs/Plex Media Server/Plex Media Server.log" | |
hddPath = "/Volumes/tank/media" | |
openAppRegex = re.compile(".* \[(.*)\] GET \/:\/websockets\/notifications .* TLS GZIP Signed-in Token \((.*)\)") | |
def wakeUpHdd(wakingUser): | |
global hddPath | |
now = datetime.now() | |
dt_string = now.strftime("%d/%m/%Y %H:%M:%S") | |
with open(hddPath+"/.wakeup", "w") as file: | |
file.write(user + " woke up hdd at: " + dt_string) | |
for line in tail("-f", plexLog, _iter=True): | |
match = openAppRegex.match(line) | |
if match: | |
ip, user = match.group(1,2) | |
print("User ", user, " logged in from ip ", ip) | |
wakeUpHdd(user) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment