[Plugin] CA User Scripts


Recommended Posts

11 hours ago, Barry Staes said:

Thanks for these wonderful Unraid Plugins!

 

Links updated

 

11 hours ago, Barry Staes said:

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.

Since I also do CA, I do not publish any URLs to any plugin installation URL.  Only CA do I publish the URL (and by implication the GitHub repository) publicly

Link to comment

I'm running the latest plugin version but since then some scripts do not get executed regularly.

 

I have 5 scripts that should run every minute but one of them is mostly running every 2 minutes and sometimes every 1 minute.

How can we fix this? Before the update the scripts were working as intended...

 

EDIT: Most of the script set to a minute interval with "* * * * *" are running in a 2 minute interval at best, and the script takes around 0.1 to 2 seconds of run time.

Even after a restart of the whole system the problem still persist. 

Edited by gekoch
Link to comment
On 2/26/2023 at 6:10 AM, Squid said:

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

IMO, having something like the following,

    #foregroundButton=[true|false]
    #backgroundButton=[true|false]

would make a lot more sense and prevent one of them becoming redundant when you use the other.

 

But my problem isn't about the wording, it's about the fact that if I use the variables at all (regardless of setting) BOTH buttons disappear, preventing me from running the script.

 

It took a bit of fidgeting to realize I had to remove the variables altogether to get the buttons back.

Link to comment

Is it a problem if a CA script I have set to run on start of the array never completes when I test with "RUN SCRIPT"?

 

During my script I call another script that is first copy into /usr/local/bin

 

In the unraid WEBUI Shell, If I run ./monitor_arrayAudioChanges.sh I am returned to the # prompt and the process runs in background fine.

If I close the RUN SCRIPT window the PID started by the monitor_arrayAudioChanges.sh is also terminated. I have tried sever suggestions I found online to have this .sh start in a different way / in background but have had no luck. Any suggestions?

 

Quote

 

## Install inotify-tools package ##
installpkg /boot/packages/inotify-tools-3.22.6.0-x86_64-1.txz

## Setup monitoring of music and audiobooks array folders ##
cp -r /boot/custom/audioArrayToSSD /usr/local/bin && chmod +x /usr/local/bin/audioArrayToSSD/sync_arrayAudioToSSD.sh && chmod +x /usr/local/bin/audioArrayToSSD/monitor_arrayAudioChanges.sh
source /usr/local/bin/audioArrayToSSD/monitor_arrayAudioChanges.sh

## Install  docker compose 
BLABLABLA


 

Edited by Presjar
Link to comment
8 hours ago, Presjar said:

Is it a problem if a CA script I have set to run on start of the array never completes when I test with "RUN SCRIPT"?

 

During my script I call another script that is first copy into /usr/local/bin

 

In the unraid WEBUI Shell, If I run ./monitor_arrayAudioChanges.sh I am returned to the # prompt and the process runs in background fine.

If I close the RUN SCRIPT window the PID started by the monitor_arrayAudioChanges.sh is also terminated. I have tried sever suggestions I found online to have this .sh start in a different way / in background but have had no luck. Any suggestions?

 

 

## Install inotify-tools package ##
installpkg /boot/packages/inotify-tools-3.22.6.0-x86_64-1.txz

## Setup monitoring of music and audiobooks array folders ##
cp -r /boot/custom/audioArrayToSSD /usr/local/bin && chmod +x /usr/local/bin/audioArrayToSSD/sync_arrayAudioToSSD.sh && chmod +x /usr/local/bin/audioArrayToSSD/monitor_arrayAudioChanges.sh
source /usr/local/bin/audioArrayToSSD/monitor_arrayAudioChanges.sh

## Install  docker compose 
BLABLABLA


 

Use "bash /usr/local/bin/audioArrayToSSD/monitor_arrayAudioChanges.sh" instead of "source /usr/local/bin/audioArrayToSSD/monitor_arrayAudioChanges.sh"
From the 1st link you provided: "In the second method, if you are using exit in second script, it will exit the first script as well."

Link to comment
1 hour ago, ICDeadPpl said:

Use "bash /usr/local/bin/audioArrayToSSD/monitor_arrayAudioChanges.sh"

Thanks! I will give that a try. I had previously tried it as per the first link, top answer, point 3. /bin/bash /usr/local/bin/audioArrayToSSD/monitor_arrayAudioChanges.sh

 

Edit: no good unfortunately. Same issue.

 

Link the script im trying to run on array start. Original script was on github. Modified to made it work for my purpose and made it messy.

https://pastebin.com/Xu5U9nAB

Edited by Presjar
Updated after testing
Link to comment
1 hour ago, explosionhole said:

Installed the User Scripts plugin, and followed the usage / guides to populate the various files.

 

After adding the script and executing it, I cannot now run in the background or schedule it for future runs.

 

Is this a known issue? Is there a fix?

Works for me.  Make sure there is no weird punctuation etc in the naming

Link to comment
On 2/26/2023 at 9:43 PM, kennymc.c said:

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.

 

Could anyone reproduce this?

Link to comment

this is my `script` syntax:


 

#!/bin/bash
#foregroundOnly=true
backgroundOnly=true
arrayStarted=true
#name=blah blah blah
#argumentDescription=This is the description of the argument(s)
#argumentDefault=defaultArg1 defaultArg2 etc

docker exec mariadb sh -c 'exec mysqldump --all-databases -uroot -p"password" | gzip > /mnt/backups/unraid_`date "+%d-%m-%Y"`.sql.gz'
find /mnt/user/data/Backups/mariadb/ -type f -mtime +15 | xargs rm

 

Link to comment

I am looking to do some automatic copying and deleting between shares for my media server.  Is there any danger just copying using the disk paths directly?  Like "cp /mnt/disk1/path/to/source /mnt/disk2/path/to/destination"?  The paths would be shares.  Or should I use "cp /mnt/user/path/to/source /mnt/user/path/to/destination"?

 

Or does it matter using this plugin?  I don't want to mess up permissions or something.

 

Thanks.

Link to comment
On 2/26/2023 at 9:43 PM, kennymc.c said:

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.

The ACE editor settings appearance bug was recently fixed in Dynamix File Manager but unfortunately these settings cannot be saved permanently. Maybe someone here knows if and how this is possible.

 

Link to comment

unable to install plugin neither via webui or cli

os version:6.12.0-rc2.

Installing info via cli:

SNAIL ~ # plugin install https://raw.githubusercontent.com/Squidly271/user.scripts/master/plugins/user.scripts.plg
plugin: installing: user.scripts.plg
Executing hook script: pre_plugin_checks
plugin: downloading: user.scripts.plg
plugin: downloading: user.scripts.plg ... done
Executing hook script: pre_plugin_checks
plugin: downloading: user.scripts-2023.03.04-x86_64-1.txz ... done

+==============================================================================
| Installing new package /boot/config/plugins/user.scripts/user.scripts-2023.03.04-x86_64-1.txz
+==============================================================================

Verifying package user.scripts-2023.03.04-x86_64-1.txz.
Installing package user.scripts-2023.03.04-x86_64-1.txz:
PACKAGE DESCRIPTION:
Package user.scripts-2023.03.04-x86_64-1.txz installed.


plugin: run failed: /usr/bin/php
Executing hook script: post_plugin_checks
SNAIL ~ #

syslog during installation:

Mar 27 02:57:32 SNAIL root: plugin: creating: /boot/config/plugins/user.scripts/user.scripts-2023.03.04-x86_64-1.txz - downloading from URL https://raw.githubusercontent.com/Squidly271/user.scripts/master/archive/user.scripts-2023.03.04-x86_64-1.txz
Mar 27 02:57:34 SNAIL root: plugin: checking: /boot/config/plugins/user.scripts/user.scripts-2023.03.04-x86_64-1.txz - MD5
Mar 27 02:57:34 SNAIL root: plugin: running: upgradepkg --install-new /boot/config/plugins/user.scripts/user.scripts-2023.03.04-x86_64-1.txz
Mar 27 02:57:36 SNAIL root: plugin: running: anonymous

diagnostics

snail-diagnostics-20230327-0258.zip

Link to comment

Can you add theme Support for the PopUp window, when i click "run script" ? 

i have a issue for me:

 

startScript.sh 

 

Quote

#!/bin/bash
echo "Script location: <b>$1</b>"
echo "<style> body {background-color: #000000} </style>"
echo "<body>"
export HOME=$(grep $(whoami) /etc/passwd | cut -d: -f 6)
source ${HOME}/.bashrc
echo "<font color='red'>Note that closing this window will abort the execution of this script</font>"
"$1" "$2" 2>&1
echo "</body>"

 

I use unraid 6.12-rc2.

 

 

I added "style" and "body" in this script and i can theme now. 

Maybe you can add theme support for the future versions.

 

I added a picture for impressions.

 

 

Picture:

Spoiler

image.thumb.png.7f538d1c2e8b9ab556146adca549f15b.png

 

regards

 

Sakashi

 

Edited by Sakashi
Link to comment

I have a question, I am not 100% familiar with scripting so someone on another group helped me out with this.

 

It's supposed to look at the trailers folder and compare it to my movies folder for a movie match and if a trailer isn't in that movies folder, and there is a match in the Trailers folder,  it will copy it over, otherwise ignore the movie folder and move on.

 

He wrote it assuming the script would be sitting in the same share (Storage-1) as the trailer and movie folder sits in. But I think with this pugin the script is in it's own folder in /boot/config/plugins/user.scripts/scripts

 

I was wondering if someone could help me put the direct paths in this script so I can get it working? Right now the paths of my share and the two folders are structured like this, with Storage-1 being the main share folder.

 

Storage-1  /  Trailers

 

Storage-1  / Movies

 

Thanks for the help! Much appriciated 

 

 

#!/usr/bin/bash

for trailer in Trailers/*; do
	echo "Searching for movie for Trailer - '$trailer'"
	basename=$(basename "$trailer" .mkv)
	basename=${basename%-trailer}
	basename=${basename/%.[[:digit:]][[:digit:]][[:digit:]][[:digit:]]/}
	basename=${basename/% ([[:digit:]][[:digit:]][[:digit:]][[:digit:]])/}
	basename=${basename/[/\\[}
	basename=${basename/]/\\]}

	matches=`find Movies -iname "$basename"\*`
	if [[ -n "${matches}" ]]; then
	    num=$(echo -n "${matches}" | grep -c '^')
	    if [[ "$num" == "1" ]]; then
		    echo "--> Found match for trailer ${matches}"
		    echo mv "$trailer" "${matches}"
	    else
		echo "Multiple matches for trailer: ${trailer}"
		echo "${matches}"
	    fi
	#else
	#    echo "--> No match found for trailer ${matches}"
	fi
done

 

 

 

 

Link to comment
18 hours ago, 1971camaroguy said:

I have a question, I am not 100% familiar with scripting so someone on another group helped me out with this.

 

It's supposed to look at the trailers folder and compare it to my movies folder for a movie match and if a trailer isn't in that movies folder, and there is a match in the Trailers folder,  it will copy it over, otherwise ignore the movie folder and move on.

 

He wrote it assuming the script would be sitting in the same share (Storage-1) as the trailer and movie folder sits in. But I think with this pugin the script is in it's own folder in /boot/config/plugins/user.scripts/scripts

 

I was wondering if someone could help me put the direct paths in this script so I can get it working? Right now the paths of my share and the two folders are structured like this, with Storage-1 being the main share folder.

 

Storage-1  /  Trailers

 

Storage-1  / Movies

 

Thanks for the help! Much appriciated 

 

 

#!/usr/bin/bash

for trailer in Trailers/*; do
	echo "Searching for movie for Trailer - '$trailer'"
	basename=$(basename "$trailer" .mkv)
	basename=${basename%-trailer}
	basename=${basename/%.[[:digit:]][[:digit:]][[:digit:]][[:digit:]]/}
	basename=${basename/% ([[:digit:]][[:digit:]][[:digit:]][[:digit:]])/}
	basename=${basename/[/\\[}
	basename=${basename/]/\\]}

	matches=`find Movies -iname "$basename"\*`
	if [[ -n "${matches}" ]]; then
	    num=$(echo -n "${matches}" | grep -c '^')
	    if [[ "$num" == "1" ]]; then
		    echo "--> Found match for trailer ${matches}"
		    echo mv "$trailer" "${matches}"
	    else
		echo "Multiple matches for trailer: ${trailer}"
		echo "${matches}"
	    fi
	#else
	#    echo "--> No match found for trailer ${matches}"
	fi
done

 

I got my issue sorted out, moving and matching trailers as expected now

 

 

 

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.