[Plugin] CA User Scripts


Recommended Posts

On 11/30/2018 at 4:42 AM, kizer said:

I have all mine goto a Cache/SSD drive. No spin ups required. 😃

 

I have a few shares

(Uploads)

   ../incoming

   ../outgoing

(Movies)

(Tv)

 

When ever I rip a movie or tv show I always send it to my (Upload) share. Then unraid via user scripts checks that upload folder and rips thru handbrake and a few other processes and then it places it in outgoing folder which FileBot looks at and then renames things and places it either in a (TV) or (Movie) share. Mover runs in the AM when my Plex Docker spools up to check my drives for new stuff moves the files onto the Protected Array off the SSD drive. 

 

My scripts run every 30 minutes so I don't have to Babysit, but the final drop to my Array/Spinner drives are at 6AM along with Plex. 

This sounds like something I want to do, albeit not as complex but a more simple version.

 

BTW, sorry for the quote on an old ass post but that's what search is for right? :)

 

I have a seedbox and I've got a LFTP script that will periodically check for files on there and pull them from my seedbox to my unRaid server. I want to know if a script can scan a specific folder (in this case, where my LFTP script dumps new downloads on my unRaid server) rename ONLY the Movie Folder name and then move them to the appropriate final destination automatically? Is this possible?

 

Seedbox > LFTP pulls files > mnt/cache/downloads/incoming > Filebot script runs > rename movie folder > move to /mnt/disk3/Media2/"4K Movies"

 

Someone said Filebot doesn't rename folders but this doesn't sound right as i've seen many posts of people doing exactly that. 

Link to comment
17 minutes ago, kizer said:

@z0ki

 

I use Filebot and it creates folders just fine for me. This is the format for mine. 
 

Transformers(2007)(720p)

/Transformers.mkv

 

So how would I create a bash script that will run after the files are pulled to my unRaid server?

 

Say you download a movie and it's folder is The.Irishman.2019.4K.HDR and I want it to be renamed only to The Irishman and then have that moved to media/"4K Movies"?

 

It sounds simple enough but the people I've asked have made it seem like it's impossible to do?

Link to comment

I have question..  I have a cron job running rysnc   but over the network or over the internet to my off site unraid..

I loose connection with rysnc it fails on its own etc..

 

how do I make a do loop to run till rsync finishes the job properly then quit...

I get this error "rsync: connection unexpectedly closed (0 bytes received so far) [Receiver]
rsync error: unexplained error (code 255) at io.c(226) [Receiver=3.1.3]"

 

so it should keep resuming till its done

 

how can I do this is it even possible

 

Link to comment
On 12/10/2019 at 10:12 AM, caplam said:

I think i solved my problem.

i had to change the first line

from


#!/usr/bin/python

to


#!/usr/bin/python3

I also had to install influxdb in a shell window:


pip3 install influxdb

Now i'm waiting for the first push to come.

If i understand right the script has to be lauched with "&" at the end off the command line in order to run without the window opened.

My bad the "run in background" button is huge but i had not seen it.

So i started the script with run un background. I also sheduled a run at array startup

 

Hi, did you get this to work?

I have a basic Python script which require a module loading but I was under the impression I had to pip3 install the module within the python script?

When you pip3 installed the influxdb module in a shell window does the ca users script plugin detect that this module is installed? I thought the shell and the ca user script were separate 'environments'?

 

Link to comment
6 minutes ago, mcfetti said:

I thought the shell and the ca user script were separate 'environments'?

They are completely different.  There are circumstances because of that environment difference where the odd script will not operate via user scripts but will at the command prompt.  Whether this affects you or not, I cannot say.  (The usage of this plugin has significantly diverged from its original design goal of doing something like simple like creating a symlink)

Link to comment
9 minutes ago, Squid said:

They are completely different.  There are circumstances because of that environment difference where the odd script will not operate via user scripts but will at the command prompt.  Whether this affects you or not, I cannot say.  (The usage of this plugin has significantly diverged from its original design goal of doing something like simple like creating a symlink)

Thanks.  I don't understand how caplam got it working then by installing a library in shell and then running his python script in the ca scripts plugin loading a module from that library

Link to comment

Hello,

 

I have a script which moves TV shows from local storage to my Google drive crypt. Can someone explain how the scheding works?

 

For example I want to set the move script to run every 10mins. However if there are a large amount of files in the directory it could take a while to finish.

 

How does user scripts handle this? Will it just not run the script or do I need to add some code in my script to handle this?

 

Hope this makes sense.

Link to comment
8 minutes ago, Squid said:

this

Okay, so I added the following to the start of the script that should work right?

if pidof -o %PPID -x "$0"; then
   exit 1
fi

 

Just thought I should add that I'm planning on having 2 scripts one for my TV Shows and one for Movies.

 

Edited by Conmyster
Link to comment
9 minutes ago, Conmyster said:

Okay, so I added the following to the start of the script that should work right?

if pidof -o %PPID -x "$0"; then
   exit 1
fi

 

Just thought I should add that I'm planning on having 2 scripts one for my TV Shows and one for Movies.

 

What I usually do is

 

  • See if /var/run/scriptName.pid exists
  • If it doesn't, write the pid to that file and execute the script
  • If it does, read the pid from the file and see if that pid is actually running.  If its not then execute the script
Link to comment
6 minutes ago, Squid said:

What I usually do is

 

  • See if /var/run/scriptName.pid exists
  • If it doesn't, write the pid to that file and execute the script
  • If it does, read the pid from the file and see if that pid is actually running.  If its not then execute the script

Hello,

 

How would you go about doing this exactly?

Link to comment
35 minutes ago, Squid said:

Taken from the mover script,


PIDFILE="/var/run/mover.pid"

if [ -f $PIDFILE ]; then
  if ps h $(cat $PIDFILE) ; then
    exit 1
  fi
fi

echo $$ >/var/run/mover.pid

.
.
.

 

Sorry I'm failing to understand how exactly that if statement works.

 

I think if I am understanding it correctly it will check if the pid file exists then if it does it will compare the current pid with the pid in the pid file. However I'm unsure what it does after that...

Link to comment

if the pid file exists and the pid actually exists, then it exits

 

The last line writes the pid of the script to the file that it checks since at that point, a previous instance of the script is no longer running.

 

The double check handles if you forget to delete the pid file when you exit normally, or if the script crashes and exits abnormally without it deleting the pidfile

 

EDIT:  You don't care about what the current PID is until you verify that a previous instance isn't already running (which will have a different PID)

 

Link to comment
3 hours ago, Squid said:

Taken from the mover script,


PIDFILE="/var/run/mover.pid"

if [ -f $PIDFILE ]; then
  if ps h $(cat $PIDFILE) ; then
    exit 1
  fi
fi

echo $$ >/var/run/mover.pid

.
.
.

 

One thing I just noticed is that when you echo the current PID into the pid file you use the full path instead of using the $PIDFILE to reference it?

 

Equally the same once the script has run I should put rm -f $PIDFILE at the end

Link to comment
16 minutes ago, Conmyster said:

One thing I just noticed is that when you echo the current PID into the pid file you use the full path instead of using the $PIDFILE to reference it?

I blame limetech, as the code is lifted from their mover script... (I do the same thing on my stuff, but use PHP -> never could wrap my head around bash scripts, variables, if / then etc

Link to comment
On 1/15/2020 at 3:16 PM, mcfetti said:

Hi, did you get this to work?

I have a basic Python script which require a module loading but I was under the impression I had to pip3 install the module within the python script?

When you pip3 installed the influxdb module in a shell window does the ca users script plugin detect that this module is installed? I thought the shell and the ca user script were separate 'environments'?

 

it worked but i wanted this to work at array startup.

The second script (which should run in background) is executed before the first one finishes installing influxdb module.

So i have to manually execute the first, wait it finishes and then run the second in backgound.

Link to comment

Hi Guys,

 

This may be a weird request.

 

I created a personal web site that I run locally - in the LetsEncrypt docker. I have coded the web site in php. I would like to create a button on the page that executes one or more of my UserScripts. Is this possible?

 

I looked at the html code for the button and it shows:

 

<input type="button" value="Run Script" class="runningNZBGetUIEdits" id="foregroundNZBGetUIEdits" onclick="runScript("/boot/config/plugins/user.scripts/scripts/My script Here/script");">

What can I do to make this executable from my web page?

 

Thank you!

 

H.

 

 

Link to comment

kinda sorta.  Not the easiest, but possible.  Of the top of my head

  • You would have to create a .page file on unRaid that would actually wind up executing the script
  • You would then point your webpage to that .page file

One initial showstopper is that without basic authorization being enabled on 6.8+ you can't actually hit that .page file without also logging in (which you can't do).  There is a hack available to re-enable basic authorization though IIRC

 

All in all, it's a big PITA because you're running head on into cross-site vulnerability issues which are being hardened by both unRaid and browsers constantly.

 

On the other hand, if by some miracle you still have unRaid version 6.0.x running then you can do this quite easily without any special tricks...

 

Link to comment

I've got an LFTP bash script that is scheduled to run every 10 minutes, but I notice if it runs and it doesn't find anything to download from my seedbox the script just keeps running and running in the background. Is there a way to make it stop with a bit of code I can put in my script that will make unRaid say "Hey, I ran the script found nothing I'll abort and try again in 60 minutes"

 

 

Link to comment
17 hours ago, Squid said:

You'd have to post the script as a start

Sure thing here you go,

 

#!/bin/bash

time lftp << EOF
set ssl:verify-certificate no
set sftp:auto-confirm yes
open sftp://user:[email protected]

mirror --use-pget-n=8 --Remove-source-dir /home/user/downloads/deluge/LFTP/"4K Movies"/ /mnt/cache/Downloads/incoming/"4K Movies"

quit
EOF

chmod -Rv 770 /mnt/cache/Downloads/incoming/"4K Movies"
chown -Rv nobody:users /mnt/cache/Downloads/incoming/"4K Movies"

mv /mnt/cache/Downloads/incoming/"4K Movies"/* /mnt/disk3/Media2/"4K Movies"

I also noticed that sometimes after say a reboot it seems LFTP will only work is I SSH into my seedbox and accept the KEY then LFTP will work again. Anyway to have my script do this automatically?

Edited by z0ki
Link to comment

I'm trying to run a ssh command through User Scripts. So I expect creating a .sh file is the right way to do that. But then how do I trigger it from User Scripts?

 

And if I want to make it more complex by giving it this command when running:

PYTHONIOENCODING=utf8

* * * * * /path/to/script.sh

How would I go about that? And what exactly should be the path if I for example put the .sh file in the User Scripts/scripts folder?

Link to comment

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.