[Plugin] CA User Scripts


Recommended Posts

I have a python script that is being ran by the user script plug in however i'm using a package that is not native to python so I was wondering how I would install it on my server so that it can be used by my script. I tried pip installing it through the command line but got some errors so im wondering if there is another way. 

 

I have the error message in this file if needed. install error message.txt

 

 

Edited by zaymus
added file
Link to comment
On 12/9/2020 at 2:48 PM, Squid said:

Yeah, it's not a bug, but by design.  Trouble is that there were so many users copying / pasting scripts from the forums here and doing that introduces other unwanted characters into the script, that all non pure ASCII characters were removed.  I'll revisit next week.

Thanks in advance.

 

IMHO: Don't modify user content in an entryfield automatically. It becomes a can of worms to decide and filter what's unwanted and what's intended. If you need to, check for unwanted characters and simply popup a small dialog "Non-ASCII characters detected. Are you sure?" and let the user decide.

 

Link to comment
On 12/9/2020 at 11:36 AM, zaymus said:

I have a python script that is being ran by the user script plug in however i'm using a package that is not native to python so I was wondering how I would install it on my server so that it can be used by my script. I tried pip installing it through the command line but got some errors so im wondering if there is another way. 

 

I have the error message in this file if needed. install error message.txt

 

My suggestion is to build a docker image (using one of the official python base images), include your python script (run it from the entrypoint) and all of its dependencies. Then run the container from your user script. 

Link to comment

Hi all,

 

Sorry for the dumb question but:

 

I want to execute a script created with the "CA User Scripts" plugin not from the Unraid GUI but from the terminal (or from another script for that matter). What is the simplest way to do so?

 

I indeed noticed that the "/tmp/user.scripts/tmpScripts" directory only contains scripts which were previously run from the Unraid GUI, and that in the "/boot/config/plugins/user.scripts/scripts" directory, the scripts permissions are set to 600 which make them not executable.

 

Many thanks,

Best

OP

Link to comment
14 minutes ago, Opawesome said:

in the "/boot/config/plugins/user.scripts/scripts" directory, the scripts permissions are set to 600 which make them not executable.

Security precaution in Unraid.

 

use this

/bin/bash /boot/config/plugins/user.scripts/scripts/.....

 

  • Thanks 1
Link to comment

I am looking for a script that would monitor a TCP port and accept commands to spinup, spindown, or return status of a disk. The the minimum capability I need would be a command to spin up all the disks in the array.  I could have them spin down after 4 hours of inactivity.  The major use of the array is to feed my own home theater movie system. The delay when loading a movie bothers me and I would like to spin up the the array disks when I open the theater's movie librarian. 

 

It is my belief that if disks are generally not being used keeping them in a spun down state will increase their longevity

 

Any help or advice would be greatly appreciated. 

Link to comment

Hello all,

 

Thought I would post my experience here since my search-fu didn't come up with an answer, and someone else may have the same issue.

 

I wanted to create a simple script to reboot my server once a week. My script worked when manually executed (RUN SCRIPT). However I was unable to make any schedule stick. I noticed that when hovering over the cog for pre-installed docker restart $(docker ps -q) no options appeared. The contents /boot/config/plugins/user.scripts/scripts contained the directory:

 

docker\ restart\ $docker\ ps\ -q/

 

I renamed this directory to docker_restart and refreshed the User Scripts page and now hovering over cog displays options and I can apply a schedule to my new script.

 

Cheers

Link to comment

I maybe having a senior moment but my system restart script is my first attempt (that I remember) at a scheduled task in unraid. I suppose I could have tried a docker restart script in the distant past and it failed because I failed to RTFM and didn't correlate the name of the script in the GUI to the directory name. Not sure how I got better at diagnosing the issue this time around though 🙂

 

Any way this can serve as a cautionary tale to others

Link to comment

Hey, anyone else experiencing non-responsive user scripts in rc1 of 6.9?  I'm finding I can't edit one at all that I've just created, can't delete it etc either.  On top of that I can't schedule any of the default ones.  Haven't tried rebooting, but that seems a bit extreme.

 

<<Edit>> Actually I think the script I added below was causing it (deleted manually at console), but oddly I didn't even get to run the script, just using the name below was enough so full stops or underscores?  Seems unlikely.  Either way, just renaming it to something basic got me going.

 

1459440218_ScreenShot2020-12-19at4_16_22PM.png.d3610a41c3aa15c3956df57ea727e2c2.png

Edited by Marshalleq
Link to comment
On 6/25/2016 at 3:41 PM, Squid said:

Just a simple little plugin to act as a front end for any little scripts that you may have that you may need to run every once in a while, and don't feel like dropping down to the command line to do it.  (Or anything that I happen to run across here on the forum that will be of use to some people)

 

Install it via Community Applications

 

Only a couple included scripts:

 

- Delete .DS_Store files from the array

- Delete any dangling images from the docker.img file

- Display the size of the docker container's log files (to see if a docker app is filling up the image file through excessive logging)

 

Additional Scripts from myself (and hopefully other users) can be found here: http://lime-technology.com/forum/index.php?topic=50416.0

 

To add your own scripts:

 

Within the flash drive folder config/plugins/user.scripts/scripts create a new folder (each script is going to have its own folder) - The name doesn't matter but it can only contain the following characters: letters ([A-Za-z]), digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), periods ("."), and spaces (" ")

 

Or, you can hit the button that says "Add Script", then give the script a name.  Hovering over the script's name will then give you additional options.  Including online editing...

Create a file called description that contains the description of the script.

Create a file called script this will be the actual script.

 

Few notes:

 

So as to make things easier for people:

  • The script file can be created with any text editor you choose.  DOS line endings will be automatically converted to Linux style endings prior to execution.
  • #!bin/bash is automatically added to every script prior to execution to help out the noobies EDIT: This is only added if no interpreter is specified (ie: #!/bin/bash)  If an interpreter is already specified (ie: #!/usr/bin/php), then line is not added

 

Various aspects of the scripts are controlled through variables contained within the scripts themselves.  This includes the description, if they can run in the background, etc.  See this post: http://lime-technology.com/forum/index.php?topic=49992.msg516885#msg516885 for more details

 

Techie Notes: 

 

The scripts are actually copied and executed from /usr/local/emhttp/plugins/user.scripts/ /tmp/user.scripts/tmpScripts so if there are dependencies (other scripts, etc) stored in the same folder as the script file, you will need to specify the full path to them.

 

 

Interactive (ie: answering yes/no to a question) scripts will not work.

 

Is there anyway I can remove the description and path rows from the USERSCRIPTS GUI page? After having a reasonable amount of scripts it gets pretty tough to have to scroll and find the script you're looking for. Having just a list of the script names would help a bit. Or if there was any way to provide some structure or add folders, it would make it much easier for me to use this plugin.

Link to comment

I wrote a script to control the fan speed through IPMI and would like it to run at 1 min intervals.

I have tested that the code runs no problem when I click on "RUN SCRIPTS" or "RUN IN BACKGROUND", however, the cron scheduling doesn't seem to work. I check the log and it doesn't show this script being executed every minute. The log does show the script executed manually when I click on "RUN SCRIPTS".

 

Anything I can do to make sure the script runs?

 

Capture.thumb.PNG.68b887777d65a1c372608c43cd07b0b9.PNG

Link to comment
9 hours ago, Hedout said:

I wrote a script to control the fan speed through IPMI and would like it to run at 1 min intervals.

I have tested that the code runs no problem when I click on "RUN SCRIPTS" or "RUN IN BACKGROUND", however, the cron scheduling doesn't seem to work. I check the log and it doesn't show this script being executed every minute. The log does show the script executed manually when I click on "RUN SCRIPTS".

 

Anything I can do to make sure the script runs?

 

Capture.thumb.PNG.68b887777d65a1c372608c43cd07b0b9.PNG

1 * * * * means to run at the first minute of every hour, every day etc.  You want * * * * *

Link to comment

This is my first User Script. I just want to back up a share that's on a single SSD Pool drive that contains my Nextcloud data to my array. (not appData. That's on my cache) Does this look OK? I got it from @hernandito . Thanks. 

 

#!/bin/bash
source="/mnt/user/nextcloud/"
destination="/mnt/user/backups/nextcloud-backup"

echo "<div style=' width: 40%; -webkit-border-radius: 8px 8px 0 0; border-radius: 8px 8px 0 0; border: solid 1px #cccccc; background-color: #ffe88a; padding-left: 10px;'><br><b><font color='black' size='2'>Backing-Up Nextcloud Folder </font><b><br>  </div>"
#echo "======================="


#echo "Backing-up from:" 
#echo "  <b><font color='blue'>"$source "</b></font>"
#echo "to:"
#echo "  <b><font color='blue'>"$destination </b></font>"


echo "<div style='width: 40%; -webkit-border-radius:  0 0 8px 8px; border-radius: 0 0 8px 8px; background-color: #ebebeb; margin-top: -14px; padding-left: 10px; padding-top: 6px;border: solid 1px #cccccc; '>Backing-up from: <br><b><font color='blue' size='2'>"$source "</b></font> <br>to:<br><b><font color='blue' size='2'>"$destination "</b></font><br> </div>"
date >/var/log/cache_backup.log
/usr/bin/rsync -avrtH --delete $source $destination >>/var/log/nextcloud_backup.log
echo ""
echo "<div style='padding-left: 10px; margin-top: -14px; '><font color='green' size='4'><b>Done!</b></font></div>"ft: 10px; margin-top: -14px; '><font color='green' size='4'><b>Done!</b></font></div>"

 

Link to comment
On 12/7/2020 at 2:27 PM, Stupifier said:

How do I run any CA Userscript Script from within a Terminal Session?

  1. I know copies of scripts are held and ran from " /tmp/user.scripts/tmpScripts"....but when I go there via Terminal...I don't see ALL of my scripts listed (only a subset). It appears the only scripts listed here are ones which have been previously executed through Userscripts GUI.
  2. I know scripts are also located in "/boot/config/plugins/user.scripts/scripts" but those are all buttoned up with permissions restricting run (probably for good reason too since its the flash drive).

Any help at all regarding this.....Sometimes its just plain easier for me to run stuff from a terminal instead of the unraid GUI....and I'd rather not clone all of my userscripts to another location just so I can run them via terminal. But if that's how its gotta be....ok....

Link to comment
9 hours ago, Stupifier said:

Any help at all regarding this.....Sometimes its just plain easier for me to run stuff from a terminal instead of the unraid GUI....and I'd rather not clone all of my userscripts to another location just so I can run them via terminal. But if that's how its gotta be....ok....

If you want to run scripts that are on the flash drive without first copying them elsewhere then use something like ‘sh path-to-script’.   This gets around the fact that scripts on the flash drive cannot be given execute permission so they can be executed directly.

  • Like 1
Link to comment

My issue is that i have a script i need to run scheduled in the background test.sh.

If i run the scripts from the userscripts page with the "run script" button it works with no issue.
However when i click "run in background" the script does not run, i have deleted the plugin and deleted it from the drive also, then reinstalled. I have a second unraid server with an identical script that runs flawlessly and now even the default scripts do not action.

 

below is the server log when i click "run script" and nothing happens

 

Jan 2 04:50:20 Email emhttpd: cmd: /usr/local/emhttp/plugins/user.scripts/backgroundScript.sh /tmp/user.scripts/tmpScripts/test/script

 

any help would be greatly appreciated.

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.