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.

[Plugin] CA User Scripts

Featured Replies

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

  • Replies 2.1k
  • Views 567.2k
  • Created
  • Last Reply

Top Posters In This Topic

Most Popular Posts

  • I could make up something long, convoluted, and technical as a reason why it doesn't do that but it would all be bs.  The simple answer is that when I did this, I never thought of that, and why it sti

  • Hi All - We have a fix and are publishing a Connect plugin update to fix it today. Thanks for letting us know.

  • @Squid I tried many commands and by that I found out that pkill does not kill (all) child processes: root@Thoth:/tmp# pgrep -f isleep2m | xargs --no-run-if-empty ps fp PID TTY STAT T

Posted Images

  • Author

 

IT's not entirely your fault.  It's on a todo list to revamp the system to allow special characters in the names without crashing the software.  It just takes a big rewrite though/

1 hour ago, Squid said:

 

IT's not entirely your fault.  It's on a todo list to revamp the system to allow special characters in the names without crashing the software.  It just takes a big rewrite though/

Thanks Squid. It's a good plugin and I certainly appreciate the time and effort you are putting in.

Hi there!

 

Is there a way to control the order of execution on the "at Array First Start?" I have three scripts that I'd like two to run BEFORE the third one runs. Does it go by the script name or by what's in the #name variable? or something else? 

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

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.

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

  • Author
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 * * * * *

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

 

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....

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.

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.

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

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

  • Author

Give me a screenshot then of the entire page

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

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

  • Author

I would try the "at" command (at NOW -m IIRC) to start your process

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. 

 

Is there a easy way to pause all scripts? (if not i suggest a pause unpause button switch)

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

 

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 

 

  • 2 weeks later...

Is there a way to schedule a script to run at the conclusion of another?

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?

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...

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.