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 can't seem to get this plugin working at all.  I've added a script which works fine when I click the run script button, however when setting a custom schedule it doesn't run at the selected time (for testing I picked 40 20 * * * as it was a few minutes in the future).  There's no entry for it in the crontab either, so not sure what I'm doing wrong here.

  • Replies 2.1k
  • Views 567.4k
  • 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

Did you press the "Apply" button at the bottom left of the screen? 

I can't recall how many times I have forgotten to do this.

On 11/10/2024 at 5:03 AM, ConnerVT said:

Did you press the "Apply" button at the bottom left of the screen? 

I can't recall how many times I have forgotten to do this.

Yeah I've hit apply.

On 11/9/2024 at 10:42 AM, alturismo said:

Hi @Squid, may a hint why user scripts have issues with umlauts when running in background

 

ok, seems i figured it

 

LC... locales, when running in background there no locales defined, so i defined them like the regular shell and its looking good now.

 

export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8

 

Hi guys,

 

I've been using CA User Scripts on Unraid to run Restic backups, but I've encountered a persistent issue: when I abort a script (using the "Abort Script" button), the Restic process continues running in the background. I have tried implementing process cleanup using trap and commands like kill 0 or pkill -TERM -P $$ to terminate all child processes, but it doesn't seem to work for Restic.

Here is my script (simplified for readability):


 

#!/bin/bash
trap cleanup SIGINT SIGTERM

cleanup() {
    echo "Cleaning up..."
    pkill -TERM -P $$ 2>/dev/null
    kill 0 2>/dev/null
}

# Main logic to run Restic
restic backup /path/to/backup &
wait

 

Even with this setup, the Restic process remains active after I abort the script. This forces me to manually log into the terminal and kill the Restic process, which is less than ideal.

 

Questions:

Is there something I'm doing wrong in the script that prevents proper cleanup of Restic processes?

 

Are there known issues with CA User Scripts or Restic in background mode that might cause this behavior?

 

Is there a better approach to ensure all subprocesses (including Restic) are terminated on script abort?

 

Any help or insights would be greatly appreciated. Thanks!

 

 

  • 2 weeks later...
On 3/15/2023 at 8:56 AM, dayvight said:

I have a problem about 502 bad gateway when i run script or run in backgroud.I tried to reinstall the plugin to no avail.

Snipaste_2023-03-15_16-38-48.png

 

Heya, did you ever find a solution for this? I'm currently experiencing the same issue but I couldn't see a reply by anyone to your post?

 

Thanks :)

  • 2 weeks later...

@Squid

can you add an option to change the order of the scripts?

also it would be nice to be able to see which scripts are enable (via cron or running) and which aren't, like a green circle or something, it's just a visual aid

Edited by L0rdRaiden

This is how I normally (quickly) verify which are active:

 

image.png.b17cb526d7e1f6730a1f05e1ed080129.png

 

Active scripts show those icons on the right. Disabled ones have no icons.

 

 

I accidentally named a script with a % sign in the title and I am unable to edit or remove the script.  How can I rename or remove it so I can add it again without the % sign?

 

Edit:

I was able to locate the scripts here: cd /boot/config/plugins/user.scripts/scripts/

 

I then deleted the problem folder and refreshed the user script plugin and everything works as normal now.

Edited by Android_18

Hello guys,

could you please help me?

I need a script, that moves the unsorted files from the folder 

/mnt/user/Pictures/unsorted

to an folder structure A to Z and 0, based on the first letter of the filename.

 

example:

/mnt/user/Pictures/unsorted/Austria-vacation_001.jpg

would be moved to:

/mnt/user/Pictures/sorted/A/Austria-vacation_001.jpg

 

/mnt/user/Pictures/unsorted/Spain_001.jpg

would be moved to:

/mnt/user/Pictures/sorted/S/Spain_001.jpg

 

I would like to start this script manually, whenever i have a few of "unsorted" Files.

 

Thanks a lot in advance!

 

 

I have figured it out by myself, if anybody needs it:

 

#!/bin/bash
target=/mnt/user/Pictures/sorted/
for f in /mnt/user/Pictures/unsorted/* ; do
  if [[ -f "$f" ]]; then
    i=${f##*/}
    i=${i:0:1}
    dir=${i^}
    if [[ $dir != [A-Z] ]]; then
      mkdir -p "${target}/0-9" && mv "$f" "${target}/0-9"
    else
      mkdir -p "${target}/$dir" && mv "$f" "${target}/$dir"
    fi
  fi
done

 

 

 

Edited by ladidaaa
solution

Hello,

 

I named my script :

Exctinction manuelle (Changer le delais !) 

 

... but I don't think it likes exclamation marks or brackets. When I click on the wheel on the left, nothing happens. I don't have any problems with my other script names that don't contain any special characters.

  • Author
3 minutes ago, Alex.b said:

exclamation marks

Probably the exclamation point immediately followed by the bracket.  Putting in a space between the two might fix

Hello, I just have a request, if possible.

 

When using the "ADD NEW SCRIPT" button, if there is a space at the end of the script name, it won't create it.

 

I was copy/pasting a name and it had a extra space at the end. It took me a good amount of time to realize that was the issue.

 

I can remember this going forward, but for others & new users, is it possible to remove any spaces at the end of the script name after input or pressing "OK" so there's no confusion?

Hmm. Is it possible to put other illegal characters in there? That's a bug either way.

On 9/14/2024 at 5:32 AM, Daburgers said:

 


Managed to fix the issue:
 

The issue was that the system time in unraid was incorrect - even though I had manually set it correctly.

 

I noticed my server was actually powering down, but not at the right time. So that made me think it had to be my date & time settings. So I checked them again for the 4th time, and this is when I noticed the issue.

 

Although they were set correctly, for some strange reason the "New date & time" at the bottom of the settings was not correct.

 

So I decided to use NTP servers to see if that made any difference....and it did. The time adjusted correctly.

I tested out my script again with a new schedule and BOOM - it worked.

 

Attached is an image of my settings before and after I made the changes in case it helps someone else:

image.thumb.png.415354aa1dcd00f2e4f1472164def529.png

I have the same issue but my time is fine and i have been trying different NTP and this still happens for me on Unraid 7 rc1.

 

  • 3 weeks later...

I seem to be unable to copy a folder into the user.scripts/scripts folder on my flash. Is this intentional?

Let's say I've setup a user script on unraid and want to copy the script's folder to use the same on another; how am I expected to carry this out? I can't see how to get files to cross the flash/array barrier. It feels like I have to use the UI to make the script, then just edit (copy/paste) into the files that user.scripts plugin made for me, but I feel like I should be able to drop a folder in and make use of it.

Is this not the case? Am I crazy, missing something?

 

Edit: From the future...

I wound up just creating the script again on the second unRAID server. I feel like there was another time I was attempting to copy something else between the flash and a share and I couldn't get it, had to copy to another share first, perhaps. I don't remember. I forget what or why by now, though. I'll circle back if I run into it again...

Edited by It's just J.

Did you try rebooting after adding them?

A lot of stuff from the flash is only loaded at boot. If that doesn't help then it's probably that it's using schedule.json as a list of existing scripts and that would need updating.

 

 

  • Author

There should be no problem.  Presumably you've exported the flash drive, but you should also ensure that a user is set for access and Windows has issues with public shares with their latest releases

What is the difference between :

 

- At startup of Array

- At First Array Start Only

 

If I understand correctly, the first option will run every time I start the array, whereas the second will only run when the array is started for the first time (basically when the server is started or rebooted), right?

 

Thank you !

 

  • Author
4 minutes ago, Alex.b said:

the first option will run every time I start the array, whereas the second will only run when the array is started for the first time (basically when the server is started or rebooted), right?

correct

Just now, Squid said:

correct

What a quick response Squid, many thanks !

I've run into a problem where the APPLY button will not save any scheduling settings. I tried to delete and reinstall the plugin, but I received no love. I'm looking for suggestions. Thank you.

  • Author

Works fine for me.  Any weirdly named scripts?

This has been happening a while...

 

webGUI: error: /plugins/user.scripts/exec.php - missing csrf_token


This happens whenever I try to schedule another script, and persists after the UnRAID 7.0 upgrade.  I can't schedule any more scripts.

Hello,

Is it possible to prevent the logfile output or redirect the logfile to a different storage device?

I am running a large backup with rclone, and it generates a 4 GB logfile, which is probably written to the USB stick. If this runs every week, it's not ideal for the stick.

Translate with ChatGPT (SORRY)

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.