January 11, 20206 yr I'm new to Unraid and recently upgraded my server from Windows 10 and have been successful in replicating almost everything (Plex, Radarr, Sonarr, etc.) except this Python code I had scheduled to run (via a Windows batch script) every day. It simply looks for files in a folder with a certain word and replaces it with another. Is there a better way to do this in Unraid (maybe without Python), or what is the easiest way to schedule Python code to be run? Also, would I have to change anything in the code to get it to work? Right now, I have a share called "movies" that I would want it to search through and I'm not sure what that file path would look like in the Python code (I'm not very familiar with Python either). from glob import glob import os files = glob("X:/Media/Movies/**/*") for f in files: os.rename(f, f.replace("-Radarr", "-TigoleQxR"))
January 11, 20206 yr 1 minute ago, HALPtech said: what is the easiest way to schedule Python code to be run? user scripts plugin
January 11, 20206 yr Author 3 minutes ago, Squid said: user scripts plugin This looks promising. Are there any guides on how to set it up to run a Python script?
January 11, 20206 yr Don't use python. I would think though that instead of it's default #!/bin/bash at the beginning, switch it to #!/usr/bin/python
January 11, 20206 yr Community Expert NerdPack plugin to install Python: https://forums.unraid.net/topic/35866-unraid-6-nerdpack-cli-tools-iftop-iotop-screen-kbd-etc/ User Scripts plugin as mentioned to schedule script: https://forums.unraid.net/topic/48286-plugin-ca-user-scripts/ The user shares are at /mnt/user, so a Movies share is at /mnt/user/Movies. Note that Linux is case-sensitive. Python is not one of my native tongues so I will leave that as an exercise for the reader.
January 11, 20206 yr 4 minutes ago, trurl said: NerdPack plugin to install Python: Yeah, can never remember if it was included in the base OS or not. (But looking at my nerdpack settings, it is set to install. No idea though why I have it doing that)
January 11, 20206 yr Author 10 minutes ago, trurl said: NerdPack plugin to install Python: https://forums.unraid.net/topic/35866-unraid-6-nerdpack-cli-tools-iftop-iotop-screen-kbd-etc/ User Scripts plugin as mentioned to schedule script: https://forums.unraid.net/topic/48286-plugin-ca-user-scripts/ The user shares are at /mnt/user, so a Movies share is at /mnt/user/Movies. Note that Linux is case-sensitive. Python is not one of my native tongues so I will leave that as an exercise for the reader. Is my Python script saved within the script file that User Scripts will run, or do I need to write a script that will invoke my Python script?
January 11, 20206 yr Author 12 minutes ago, Squid said: either or. If there's problems, then have a bash script call the python one. Okay. I installed Python via the NerdPack, and then created and ran the following script via User Scripts: from glob import glob import os files = glob("mnt/user/test_share/**/*") for f in files: os.rename(f, f.replace("-BeepBopBoop", "-Test")) And got the following result: The script ended up not changing the expected file name. Any thoughts on what might be happening? "From" and "import" are Python commands, so I'm not sure how to get User Scripts to recognize that it's running a Python script. If I save the actual Python code as pythoncode.py, how would I invoke that via the script? That may be the easier way to do it. Edited January 11, 20206 yr by HALPtech
January 11, 20206 yr Author 4 minutes ago, Squid said: Is the first line still #!/bin/bash? Change it to #!/usr/bin/python Here's what I get when changing the first line to #!/usr/bin/python: It would seem installing python didn't install a directory it was supposed to have? (I've confirmed it is downloaded, installed, and turned on in the NerdPack settings.) Edited January 11, 20206 yr by HALPtech
January 11, 20206 yr From the command prompt, which python should return /usr/bin/python unless you installed python3 in which case you need to use #!/usr/bin/python3
January 11, 20206 yr Author 1 minute ago, Squid said: unless you installed python3 in which case you need to use #!/usr/bin/python3 That worked! I had installed python3. One last question - do I need to run some sort of exit command in my script, or will it automatically stop running after it looks through all the folders in the share I specified?
January 11, 20206 yr If running it manually brings up a DONE button when it's finished, then no. I suppose it doesn't hurt to include it anyways
Archived
This topic is now archived and is closed to further replies.