Skip to content
View in the app

A better way to browse. Learn more.

Unraid

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

What's the best way to schedule this Python to run on a regular schedule?

Featured Replies

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"))

 

1 minute ago, HALPtech said:

what is the easiest way to schedule Python code to be run?

user scripts plugin

  • 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?

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

  • 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.;)

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)

  • 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?

either or.  If there's problems, then have a bash script call the python one.

  • 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:

 

image.thumb.png.17a227a367e8ea671ffd2f3b51113e09.png

 

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 by HALPtech

Is the first line still #!/bin/bash?  Change it to #!/usr/bin/python

  • 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:

 

image.thumb.png.2e90e51fef1436fdb24a19aa540460c0.png

 

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 by HALPtech

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

  • 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?

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.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.