[Plugin] CA User Scripts


Recommended Posts

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
3 minutes ago, HarryD said:

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.

Any punctuation in the description?

Link to comment
3 minutes ago, Squid said:

Any punctuation in the description?

i might miss-understand what you're saying? sorry if my original post was not clear.

When i attempt to run the script in the image below, clicking the "Run in background" button, nothing happens.

 

script is identical to the one i use on another unraid server without issues. however even the default scripts that come with the 'userscripts' plugin do not run in background.

image1.PNG

Link to comment
3 minutes ago, Squid said:

Give me a screenshot then of the entire page

full page screenshot, brings up "script running window" as normal but script does not actually run in background and doesn't bring up the usual "running"

image2.PNG

image3.PNG

image2.PNG

Edited by HarryD
Link to comment

I am trying to run some command and push them the in background but the GUI terminal seems to get stuck and the script doesn't really seem to finish (I do not see the echo in the window and running ps aux | grep avahi-publish show the process does not exist).

Any suggestions?

#!/bin/bash
#description=Generate avahi aliases
#foregroundOnly=true
#name=Avahi aliases (sub-domains)

echo "plex.inas.local"
/usr/bin/avahi-publish -a -R plex.inas.local $(avahi-resolve -4 -n inas.local | cut -f 2) &

 

Edited by sdfyjert
Link to comment
On 1/1/2021 at 1:33 PM, HarryD said:

full page screenshot, brings up "script running window" as normal but script does not actually run in background and doesn't bring up the usual "running"

image2.PNG

image3.PNG

image2.PNG

From what I remember that's normal. Otherwise there would be an error saying. If you close this box it will shut down the script. 

 

Simply click the close button it will continue running in the background. 

 

Link to comment

Trying to run a script that deletes all folders under a certain size (which works perfectly) but I need to exclude 1 folder and I can't get the syntax right.  Help?

 

#!/bin/bash
shopt -s extglob
du /mnt/user/media/Movies/ | awk '$1 <= 300000 { print "rm -rf -v \"" substr($0, length($1)+2) "\" !(".stfolder")"}' | sh
awk: cmd. line:1: $1 <= 300000 { print "rm -rf -v \"" substr($0, length($1)+2) "\" !(".stfolder")"}
awk: cmd. line:1:                                                                     ^ syntax error

 

Link to comment
5 hours ago, Fffrank said:

Trying to run a script that deletes all folders under a certain size (which works perfectly) but I need to exclude 1 folder and I can't get the syntax right.  Help?

 


#!/bin/bash
shopt -s extglob
du /mnt/user/media/Movies/ | awk '$1 <= 300000 { print "rm -rf -v \"" substr($0, length($1)+2) "\" !(".stfolder")"}' | sh

awk: cmd. line:1: $1 <= 300000 { print "rm -rf -v \"" substr($0, length($1)+2) "\" !(".stfolder")"}
awk: cmd. line:1:                                                                     ^ syntax error

 

Solved my own problem and wanted to post the solution.  I added the if statement for exclusion to the awk routine rather than asking asking the rm command to ignore.

 

du /mnt/user/media/Movies/ | awk '{ if ( $1 <= 300000 && $2 != "/mnt/user/media/Movies/.stfolder" ) print "rm -rf -v \"" substr($0, length($1)+2) "\"" }' | sh 

 

Link to comment
  • 2 weeks later...

So, I'm having some issues with a docker... those issues aside, I'm looking for a script to schedule a docker reboot regularly, such as every 2 hours or so. 

 

I have been working to resolve the core issue but thus far, the only resolution I have found is to restart the problem docker. anyone have a script that can accomplish this?

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.