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

Are users able to organize their scripts into folders similar to folders for Docker containers via the FolderView2 plugin?

I've got a lot of scripts, not all of which are given a schedule, but they're there for use when necessary. Sifting through them in alphabetical order rather than what I'm likely to want at any given moment makes the whole thing quite cumbersome to manage after a while.


Even a config option to set a default view that allows filtering Schedule Disabled to the bottom in a separate/divided list, just like how the Main view separates out the array and pools.

I also find the lack of alternating colors like in the Main page the Unraid admin GUI makes it extremely hard to parse at a glance.

Versioning scripts via Git and being able to pull a Git repository of scripts in would be amazing. I've messed up scripts on a few occasions and lamented the inability to quickly revert back to a previous, diff, or be able to update the scripts from a repository without fiddling around in the GUI.

Excellent plugin overall, but oodles of untapped potential. :- )

  • 2 weeks later...
  • Replies 2.1k
  • Views 567.1k
  • 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

Is there a difference between normal crontab jobs and how User Scripts is scheduling jobs?

I have a script that I want to run on every first Monday of each month. I have setup User Scripts to use a custom schedule with the following syntax:

30 1 */32,1-7 * 1

which according to https://crontab.guru/#30_1_*/32,1-7_*_1 should do exactly what I need. However Unraid seems to run this script on every Monday instead:

image.png


My configs seem to be correct though:

image.png

root@blackbox:~# cat /boot/config/plugins/user.scripts/customSchedule.cron

...
# Generated cron schedule for user.scripts
30 1 */32,1-7 * 1 /usr/local/emhttp/plugins/user.scripts/startCustom.php /boot/config/plugins/user.scripts/scripts/12_backup_monthly/script > /dev/null 2>&1
...

The script is also correctly scheduled in /etc/cron.d/root:

root@blackbox:~# cat /etc/cron.d/root

...
# Generated cron schedule for user.scripts
30 1 */32,1-7 * 1 /usr/local/emhttp/plugins/user.scripts/startCustom.php /boot/config/plugins/user.scripts/scripts/12_backup_monthly/script > /dev/null 2>&1
...

Why is this not working as expected and how can I fix it? Unraid bug?

Thank you very much!

Edited by Tom082

Hi,

Fairly new to unraid, and not super computer literate compared to most people with a server...

I'm trying to run a script to change files from hi.srt to sdh.srt. I started a dry run first and everything appeared right so I took that block out and ran it properly. The whole time going through it was letting me know it was renaming files and I didn't see it error out at all. However when it finally finished absolutely nothing was renamed. Just need some help understanding why and what I should change (and ideally why I should change it, so I can learn how this works for future scripts). Script is as follows

#!/bin/bash

echo "=== STARTING SRT RENAME SCRIPT ==="

# Hardcoded root folder

root_folder="/mnt/user/data/media"

# Find and process .hi.srt files

find "$root_folder" -type f -name "*.hi.srt" -print0 | while IFS= read -r -d '' file; do

new_file="${file%.hi.srt}.sdh.srt"

if [ "$dry_run" = true ]; then

echo "[DRY-RUN] Would rename: $file -> $new_file"

else

# mv "$file" "$new_file"

echo "Renamed: $file -> $new_file"

fi

done

Thanks in advance for any help :)

51 minutes ago, obsidianwings said:

# mv "$file" "$new_file"

Remove the # at the start - you've effectively remmed / commented out this line, so the actual renaming is skipped

Oh, that simple, wow 😂 thank you will take a look at this on the morning. It said it was renaming them so I wasn't expecting that to be the answer. Appreciate it

Edited by obsidianwings

23 minutes ago, obsidianwings said:

Oh, that simple, wow 😂 thank you will take a look at this on the morning. It said it was renaming them so I wasn't expecting that to be the answer. Appreciate it

Yeah, the "echo" line after is is what's telling you it's renaming, but since the actual command doing the work was commented out you were effectively doing a dry run. The echo command could say pretty much anything, so feel free to change it to echo "renamed $file, transferred money into bank account 😀

5 hours ago, Cessquill said:

Yeah, the "echo" line after is is what's telling you it's renaming, but since the actual command doing the work was commented out you were effectively doing a dry run. The echo command could say pretty much anything, so feel free to change it to echo "renamed $file, transferred money into bank account 😀

Makes total sense, thank you 😂

Inline variables described under "HOW TO ADD SCRIPTS" do not work:

test script:

#!/bin/bash

backgroundOnly=true

argumentDescription=TEST

Run in Background button is still enabled, description is not set to TEST

I was hoping the latest update would fix this, but no luck...

For at least a year, I have been unable to schedule a script. When I try to apply a custom schedule, I get a log error of "/plugins/user.scripts/exec.php - missing csrf_token" and the schedule doesn't apply. It worked for 259 other scripts, but since one year ago, I can't schedule another one.

I've tried disabling plug-ins, etc... Nothing works.

I am currently getting a "127" error when trying to update to the latest version. Is there a way to run a more verbose output or manually run the update to troubleshoot why it's failing?

Thank you!

  • 4 weeks later...

Hi, I'm trying to set up a bash script that spends my bonus points on MAM but this script requires access to some json files that it creates to maintain an active session on MAM. Is there a way to make user scripts keep these files persistent? I also tried setting the bash script within one of my docker containers and running it on a cron job but it doesn't run so I'm guessing cron doesn't work within these containers

  • 2 weeks later...

Is anyone having trouble manually firing off a script? I hit the Run in Background button and it acts normally however, the script never runs. BUT, the cron schedule for the script DOES run properly at its allotted time. No idea how long this has been going on since it has probably been 2 months since I manually ran some scripts. And my server has been powered cycled since then, but again, no idea when manual script firing stopped, maybe it was after the power cycle and I need to do it again.

Just curious.

Thanks!

Why is "users scripts" on the settings menu and not on the tools menu?

ok, it's just me, isn't it?

Not sure if this is a potential bug but i created a new script and called the script:

"Link Overlay2 folders to Container Names! (troubleshooting)"

After creating the new script name in the userscipt plugin, the settings cog for the new script dosn't load when clicked on so i'm stuck with this entry and cant delete it, edit it or do anything with it. It's just become stale!

Assuming that the way the name has been parsed to the plugin has caused some sort of weird glitch. Likely either the "!" or the "(" or ")" symbols.

Can anyone do a quick test to see if they experience the same issue? Add new script > give it the name above in bold. Save. Then try and delete it.

Where would be best to post this to get it looked at potentially?

Edited by thestraycat

  • 5 weeks later...

Could you possibly mention in the instructions that the arguments that you enter in the comments at the top of the script are then called as positional arguments? The instructions seem so explicit but then just neglect to mention that. It may seem obvious to most, but I was trying to figure out what the arguments were named, if "argumentDefault" was like a placeholder name and we were supposed to change it, or what. It was infuriating until I figured it out. Just a simple "First argument is called as $1, second is $2".. etc. I am sure a lot of newbs and non-newbs alike would find it useful.

Hello everyone.

I have two problems at the moment with the user scripts plug-in.

  1. I can't delete some scripts. I click on the gear but nothing happens. is there another way to delete them?

  2. I can't set custom schedules. I select custom, add the cron code like */3 * * * * click apply and done. But when I enter user scripts again it's set to schedule disabled.

Any ideas to solve the issues?

Thanks ahead!

I had similar issues, had to delete the script manually from the userscript folder via terminal. Not sure when or why it broke.

46 minutes ago, thestraycat said:

I had similar issues, had to delete the script manually from the userscript folder via terminal. Not sure when or why it broke.

Thanks for the fast reply.

That worked for me also. I deleted a few old unused scripts and now the custom scheduler is working

Good to hear - Yeah i feel the userscripts plugin might need some love....

For some reason this script only work when i run it myself i want to run it in the background. if i try that it doesnt do anything

#!/bin/bash

#clearLog=true

# Explicitly set the PATH to ensure necessary commands are found in background jobs.

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

# Define log file and a persistent log path.

# This ensures a clean log for each run and a persistent backup.

LOG_FILE="/tmp/user.scripts/tmpScripts/Hetzner_Storage/log.txt"

PERSISTENT_LOG_PATH="/mnt/user/appdata/rclone/hetzner_storage.log"

# Create the persistent log directory if it doesn't exist

mkdir -p "$(dirname "$PERSISTENT_LOG_PATH")"

# Execute the rclone command and capture the output to a variable.

RCLONE_OUTPUT=$(rclone about hetzner: --log-level INFO 2>&1)

# Extract the free space from the rclone output.

FREE_SPACE_STR=$(echo "${RCLONE_OUTPUT}" | grep "Free:" | awk '{print $2}')

# Clean up the string to get a number.

FREE_SPACE_GB=$(echo "${FREE_SPACE_STR}" | sed 's/GBytes//')

# Check if free space is less than 50 GB and send a notification if true.

# We'll use a simple shell check to compare floating-point numbers.

if [ -n "${FREE_SPACE_GB}" ]; then

# Use a subshell to perform the comparison without bc.

# This rounds down the GB value to the nearest whole number before comparing.

INTEGER_FREE_SPACE=$(echo "${FREE_SPACE_GB}" | cut -d'.' -f1)

if [ "${INTEGER_FREE_SPACE}" -lt "50" ]; then

/usr/local/emhttp/webGui/scripts/notify -e "Hetzner Storage Alert!" -s "ATTENTION: Hetzner Storage Free Space Low" -d "Hetzner storage has less than 50GB of free space. Current free space: ${FREE_SPACE_GB} GBytes." -i warning

fi

fi

# Write the rclone output to a temporary log for the plugin widget.

echo "${RCLONE_OUTPUT}" | tee "${LOG_FILE}"

# Append the contents of the temporary log to the persistent log

cat "${LOG_FILE}" >> "${PERSISTENT_LOG_PATH}"

  • Author

You have to bear in mind that running stuff via the plugin doesn't exactly run it in a shell. Rather it's all ultimately executed from within a PHP script, so there are slight differences including what you already noticed where not all the PATHS are defined

I wanted to ask, if you also noticed that the plugin has a visual issue when updating unRAID to 7.2.0 beta. Unlike previous unRAID versions, there's no space between the last two elements.

It's not a big deal, but it looks ugly (especially because the lines are not at the same height).

until 7.2.0 beta
image.png

With 7.2.0 beta

image.png

Edited by petbrau

7.2 userscripts has some formatting issues, schedule field is to close to the custom schedule fieldimage.png

I have the User Scripts Enhanced plugin installed. All the features including exports seem to work fine, with the exception of Export Config. If I select: Settings > User Scripts Enhanced > Export Config, it returns "Error: File not found." Any suggestions on what could be causing this error? Thanks.

  • 2 weeks later...

Hi,
I have a script I need to run when my pool starts. Looking at the options, there is one for array start but will that still work in my case as I don't have an array, I only have a zfs raid-z2 pool. Will the run on array start still work?

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.