[Plugin] CA User Scripts


Recommended Posts

When tmux has no running sessions and I start a new tmux session on one of my bash scripts via User Scripts' GUI, tmux is started without sourcing .tmux.conf (at least based on it looking incredibly bare-bones and none of my keybinds working).

 

When I run the same script in the terminal by just running `bash <SCRIPT>`, tmux is started perfectly fine with .tmux.conf sourced. I've tried changing the script to a zsh script and a sh script, but neither has worked.

 

Curiously, when there are already other tmux sessions running, the User Scripts-created tmux session sources .tmux.conf perfectly fine.

 

Does anyone know any possible fixes to this? Thanks in advance

Link to comment
On 10/17/2022 at 3:46 PM, Unpack5920 said:

Small Feature-Request

 

Could you please sort the User Script List by name.

I use script names like:

  • backup-share_docker
  • backup-share_appdata
  • cleanup-delete_ds_store
  • power-force_sleep
  • ...

Sorting would group them accordingly

Thank you in advance.

 

I would also like if it's possible to sort the scripts by name. I like the idea of having the scripts that run scheduled on top of the list and having all others below. So if you have time, it would be cool, if you could implement this feature. :)

  • Upvote 1
Link to comment

This may be a dumb question but I can't find any FAQs or source code. 
First, does running something in the background lockout any other script from running on schedule? 
If not, is there a way I can ensure that a script runs at startup and is always running?

 

Link to comment
8 hours ago, OddOod said:

First, does running something in the background lockout any other script from running on schedule? 

nope, they run individually so you can run them parallel

 

8 hours ago, OddOod said:

If not, is there a way I can ensure that a script runs at startup and is always running?

 

make sure your script runs and doesnt exit, sample in a while loop ...

 

here a sample how it looks while a script runs perm while others are just running on schedule, if thats the question.

image.thumb.png.180233f0c4fec8ac463a727c27e1ea78.png

  • Like 1
Link to comment

Is there a way to get a script to only send a notification if at least one of the move commands moved something/ did not return the error

"mv: cannot stat '/mnt/user/data/example*': No such file or directory"

 

I get this error because I run 8 simple mv commands in the script and if just one of them finds nothing to move I get the error, which means I can't use and if exit code statement in the notify script. I only want to be notified if one or more of them move something.

 

/usr/local/emhttp/webGui/scripts/notify -s "example" -i "normal" -d "example"

is what is set currently at the bottom of the script.

Link to comment

I created a script for elasicsearch as per several online tutorials, but it caused issues with unraid, and my nextcloud kept crashing.

I tried to remove the script, but it still seems to run every day or so. I removed the User Script plugin. I manually removed the script from config, but it seems to still be trying to run, and it brings down the server. I have to do a full reboot of the server to get nextcloud to work again.

Where can I look to find the rogue script?

 

Edit: It seems there are a few issues with the server. I made to many changes so I may just revert all changes back to basic install.

 

I am think this is an issue from logs:

emhttpd: cmd: /usr/local/emhttp/plugins/dynamix/scripts/share_size ncdata ssz1

 

Any advise to point me in the right direction would be appreciated.

Edited by graphius
update troubleshooting
Link to comment

I am after a bit of script help - I have much of this done, but I cant get three areas below working with variables - all other parts are 'variablised' - if that is a word - once these are done, I can copy this script to others and just edit the appdata_folder and container_name variables for all new containers I want to do on their own :

 

Issue 1 - I cant get the syntax of the docker inspect command correct if I pass in a container name variable.  

The command I want to run is

container_running=`docker inspect -f '{{.State.Running}}' jackett`

but I want to pass in the 'jackett' from the variable $container_name

The variable setup is container_name=jackett 

 

Issue 2 - 

num_files=`ls /mnt/user/Backups/appdata_automatic_backups/jackett_backup_*.tar.gz | wc -l`

but I want to pass in two variables to make all this up before the _backups bit :

backup_dir="/mnt/user/Backups/appdata_automatic_backups"
appdata_folder="jackett"

 

Issues 3 - But lielkyl the same fix as 2 - 

oldest_file=`ls -t /mnt/user/Backups/appdata_automatic_backups/jackett_backup_*.tar.gz | tail -1`

but I want to pass in two variables to make all this up before the _backups bit :

backup_dir="/mnt/user/Backups/appdata_automatic_backups"
appdata_folder="jackett"

Link to comment

curious is this will allow for user input while the script is running. really wanted to add something like this

 

ask_user() {
  read -p "Do you want to continue with the script? (y/n): " choice
  case "$choice" in 
    y|Y ) echo "Continuing with the script...";;
    n|N ) echo "Exiting script..."; exit;;
    * ) echo "Invalid input. Exiting script..."; exit;;
  esac
}

 

Link to comment

Hello Friends,

Can someone explain how I can use User Scripts to automatically backup several different data folders on my UnRAID server to an unattended device?

I would like the script to run automatically every X days and keep the last Y backups (earlier backups than Y can be deleted or overwritten).

Is this possible?

Thank you for your help 🙏

Link to comment
7 minutes ago, mjeshurun said:

Hello Friends,

Can someone explain how I can use User Scripts to automatically backup several different data folders on my UnRAID server to an unattended device?

I would like the script to run automatically every X days and keep the last Y backups (earlier backups than Y can be deleted or overwritten).

Is this possible?

Thank you for your help 🙏

 

Ein mögliches Script wäre dies:
(This sichert my USB Stick) - must dies nur an deine Bedürfnisse anpassen.
Ich habe dieses aus einem anderen Thread - es stammt auch nicht von mir.

 

#!/bin/bash

#### SECTION 1 ####------------------------------------------------------------------------------------------------------
#dir = WHATEVER FOLDER PATH YOU WANT TO SAVE TO
dir="/mnt/disk3/flash_backup/"

echo 'Executing native unraid backup script'
/usr/local/emhttp/webGui/scripts/flash_backup

#### SECTION 2 ####------------------------------------------------------------------------------------------------------
echo 'Remove symlink from emhttp'
find /usr/local/emhttp/ -maxdepth 1 -name '*flash-backup-*.zip' -delete

sleep 5

#### SECTION 3 ####------------------------------------------------------------------------------------------------------
if [ ! -d "$dir" ] ; then
 
            echo "making directory as it does not yet exist"

            # make the directory as it doesnt exist
            mkdir -vp "$dir"
        else
            echo "As $dir exists continuing."
            fi


#### SECTION 4 ####------------------------------------------------------------------------------------------------------
echo 'Move Flash Zip Backup from Root to Backup Destination'
mv /*-flash-backup-*.zip "$dir"

sleep 5

#### SECTION 5 ####------------------------------------------------------------------------------------------------------
echo 'Deleting Old Backups'

#ENTER NUMERIC VALUE OF DAYS AFTER "-MTIME +"
find "$dir"* -mtime +15 -exec rm -rfv {} \;

echo 'All Done'

#### SECTION 6 ####------------------------------------------------------------------------------------------------------

#UNCOMMENT THE NEXT LINE TO ENABLE GUI NOTIFICATION UPON COMPLETION 
#/usr/local/emhttp/webGui/scripts/notify -e "Unraid Server Notice" -s "Flash Zip Backup" -d "A copy of the heimnas-server unraid flash disk has been backed up" -i "normal"

exit

 

  • Like 1
Link to comment
On 1/24/2023 at 12:19 PM, Fabian Hammer said:

 

A possible script would be this:
(This secures my USB Stick) - just need to customize this to suit your needs.
I got this from another thread - it's not mine either.

 

#!/bin/bash

#### SECTION 1 ####------------------------------------------------------------------------------------------------------
#dir = WHATEVER FOLDER PATH YOU WANT TO SAVE TO
dir="/mnt/disk3/flash_backup/"

echo 'Executing native unraid backup script'
/usr/local/emhttp/webGui/scripts/flash_backup

#### SECTION 2 ####------------------------------------------------------------------------------------------------------
...

 

Thank you, @Fabian Hammer 🙏🙏
Can you please share the link to the other thread you got the script from? 🙏

To be honest, I'm not a developer so I don't completely understand what each line in the script does. 

So I would like to read more about it and understand how each part works.

Link to comment
11 minutes ago, mjeshurun said:

Thank you, @Fabian Hammer 🙏🙏
Can you please share the link to the other thread you got the script from? 🙏

To be honest, I'm not a developer so I don't completely understand what each line in the script does. 

So I would like to read more about it and understand how each part works.

 

Ich finde diesen Thread leider nicht mehr da es schon eine weile her ist.
Es sind jedoch hier im Forum einige findige Menschen unterwegs die dir sicherlich besser helfen können als ich.
Ich denke da gleich an @SpaceInvaderOne, @mgutt, @ich777@knex666 - die machen hier bei Unraid vieles möglich.
Hier auch gleich einmal einen liebes Dankeschön an Euch für die tolle Arbeit.

Ich kann dir zeitgleich auch noch einen anderen Thread empfehlen:

 

Edited by Fabian Hammer
  • Like 1
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.

 

These Links dont resolve anymore. Does anyone have the script list?

Link to comment
  • 3 weeks later...

Is it possible to install `test` to use comparators in Bash on unRaid? I have a script to check for missing hard links and to alert me via Pushover if found. The issue is I do not think `if [ $NO_DUPLICATES_FOUND_TEXT_COUNT -eq 0 ]; then` is supported in Unraid

 

 

 

PUSHOVER_APP_TOKEN=""
PUSHOVER_USER_TOKEN=""
PUSHOVER_MESSAGE="Override this with message"

JDUPE_RESULTS=$(jdupes -M -r -Q "/mnt/user/data/torrents/" "/mnt/user/data/media/")
echo $JDUPE_RESULTS
NO_DUPLICATES_FOUND_TEXT_COUNT=$(echo $JDUPE_RESULTS | grep -c "No duplicates found")
DUPLICATES_FOUND=false
if [ $NO_DUPLICATES_FOUND_TEXT_COUNT -eq 0 ]; then
# No duplicates text not found, there are potential duplicates
DUPLICATES_FOUND=true
PUSHOVER_MESSAGE="A Jdupe quick scan indicated $NO_DUPLICATES_FOUND_TEXT_COUNT missing available hard links. This can be fixed with other userscripts in the userscripts plugin"
curl -X POST -H "Content-Type: application/json" -d "{\"token\": \"${PUSHOVER_APP_TOKEN}\", \"user\": \"${PUSHOVER_USER_TOKEN}\", \"message\": \"${PUSHOVER_MESSAGE}\"}" https://api.pushover.net/1/messages.json
echo "Duplicates were found"
exit 1
fi
PUSHOVER_MESSAGE="A Jdupe quick scan passed: $NO_DUPLICATES_FOUND_TEXT_COUNT missing hard links"
exit 0
echo $DUPLICATES_FOUND

 

Link to comment

Relative n00b here, and I don't know if I have missed anything.

 

I have just downloaded the plugin (v2023.02.25a), and the Run In Background button does not seem to do anything.  I can run any of the 3 sample scripts using the Run Script button, but nothing happens when I try Run In Background. Watching the Log window I can see the an entry when I try the foreground script, but nothing is logged when trying it in the background.  I've also added my own script and it runs in foreground or via Custom schedule without issues, but again not via Run In Background.  Adding #backgroundOnly=true to my script hides the Run Script button, so that seems to be working in general. Anyone else have an issue, or have I missed something?

  • Thanks 1
Link to comment
On 2/20/2023 at 3:46 PM, sunbear said:

These variables no longer seem to be working.

 

#foregroundOnly=false
#backgroundOnly=true

 

If I use them both, neither buttons show up in the GUI, regardless if true or false.

 

Basically, if you define either variable, they are interpreted as TRUE.

I'll look at it, but effectively they are both the same thing just opposite ways of wording it.  Only use one of them.

Link to comment

I noticed that the ACE Editor settings (Ctrl+,) like theme or text size are not saved. As soon as you exit the User Scripts plugin and open it again, the default settings are loaded again.
There are also display problems with the Black and White Base Themes. Themes with a vertical menu bar like Azure and Grey are not affected.
The problem also affects other plugins that use the ACE editor, like Dynamix File Manager.

Link to comment
10 hours ago, coldviber said:

thanks for the quick fix, but I don't think logs are working, at least on my side I don't have any logs from the scripts.

Same for me.  Fully updated to 2023.02.26.   I'm running an rclone script and I can tell from the net traffic and the process usage that the script is running but the log only says "Script Starting Feb 26, 2023 17:01.32   Full logs for this script are available..."

Link to comment

Thanks for these wonderful Unraid Plugins!

 

I found some links are broken or missing, and for your convenience i tried to make a nice summary for CA User Scripts :

  1. Unraid page /Settings/Userscripts > bottom of the page > link "For help with this plugin, visit HERE" => points to https://unraid.net/forum/index.php?topic=49992.0 and shows an empty webpage saying "File not found.".
  2. Unraid page /Settings/Userscripts > top-right "Credits" popup, link "Plugin Support Thread" => points to https://unraid.net/topic/48286-plugin-ca-user-scripts and shows a webpage saying "error 404".
  3. Unraid page /Plugins > plugin entry "User Scripts" > does not show a "Support Thread" link in the overview, like most other plugins show.
  4. Unraid page /Apps (CA) > search "user scripts" plugin > button "Info" > in popup button "Support Forum" => points to https://unraid.net/forum/index.php?topic=49992.0 and shows an empty webpage saying "File not found.".
  5. I found no link or mention of the Unraid Plugin User Scripts source repository anywhere in the CA, plugin itself, changelog, this plugin forum thread, or your (Squid's) profile.
Edited by Barry Staes
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.