Running Shell and Python Scripts from a CLI


soong

Recommended Posts

I'm new to unRAID and to Dockers. I'm trying to run some custom shell script and Python programs and trying to figure out the "right" way to do things... I got some tests to work but I want to make sure I'm not going to cause trouble for myself down the road.

 

I have some scripts that help organize and cleanup my photos so I'll want to be able to run them on a specific folder on a specific share.

 

I'll need to be able to:

 

  • run git and download code from a repository
  • use apt-get to install programs like exiftool
  • install/use pip to install python libs
  • sometimes run the CLI in a remote window so I can leave the process/program running undisturbed
  • sometimes SSH directly into the CLI so I can run things directly on my local computer

 

This sounds like I'd want to setup a Docker for this... I also played around using the CLI accessible from the GUI but I guess that environment is only in RAM because I lose any installs once I reboot.

Link to comment
On 1/25/2020 at 4:51 PM, soong said:

but I guess that environment is only in RAM because I lose any installs once I reboot.

Correct, unRAID unpacks fresh from RAM on every boot. 

 

On 1/25/2020 at 4:51 PM, soong said:
  • use apt-get to install programs like exiftool

Technically speaking this item is the only one on the list that can't be done without using Docker/VM, due to the fact that unRAID does not have apt-get (or any common package manager for that matter).

On 1/25/2020 at 4:51 PM, soong said:

This sounds like I'd want to setup a Docker for this

While this is not the only way to do things it is definitely the one i recommend. I would start by looking on docker hub for a base image of a distro you are most comfortable using, preferably an official image or one from well known maintainer (Python images are available as well).

From there you have a couple of paths. You could pull the image, spin up a container and exec in, install all the extras you want in the container, then commit it to a new image for later use. Alternatively (and my preference) would be to write a Dockerfile that makes the customization to the base image as that will make rebuilding the image with new packages easier. 

Once you have a custom image you can either run your scripts manually from the unRAID CLI or using the user scripts plugin by spinning up a containers with the correct script. Something like

docker run --rm -v /mnt/user/share-or-path-to-files:/path-in-container:rw my-custom-image /script-in-image.py --args-for-script

or if you dont want to bake the script into the image

docker run --rm -v /mnt/user/share-or-path-to-files:/path-in-container:rw  -v /mnt/user/scripts:/scripts:ro my-custom-image /scripts/my-script.py --args-for-script

You will want to look at the docker run -d and -i and -t flags as they can control if the container runs like a daemon or like a script on the console.

 

 

 

 

Link to comment
  • 1 year later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.