[Plugin] CA User Scripts


Recommended Posts

On 1/7/2024 at 11:49 AM, House Of Cards said:

Love this plugin....  Thanks @Squid for all your ongoing efforts...

 

Maybe a script aficionado could help me modify this script?  I do some overly tedious scheduling of media content from a location with everything in it, to a location with "active" content.  This makes my media server constantly cycle in/out content so it's interactive.  Works great, but I have a special case where I don't want to schedule 80 scripts...

 

Don't laugh, but it's Looney Tunes, with like 40 seasons.  😆

 

Here is a basic script I would use for content in...

 


# CREATE NECESSARY SERIES DIRECTORIES
mkdir -p /mnt/user/"Television- Media Server"/"Family Guy (1999)"

# RECREATE MISSING SERIES METADATA
cp /mnt/user/"Television- All Media"/"Family Guy (1999)"/* /mnt/user/"Television- Media Server"/"Family Guy (1999)"/

# ADD CONTENT TO PRODUCTION SERVER
cp -R /mnt/user/"Television- All Media"/"Family Guy (1999)"/"Season 01" /mnt/user/"Television- Media Server"/"Family Guy (1999)"

 

I need to modify this script to create a VARIABLE between "1929" and "1969", and substitute that number for the season number in the copying commands.  All the documentation I found on this is confusing, so any help would be greatly appreciated.

 

Don't know if this will help you much, but its an idea. 

https://unix.stackexchange.com/questions/468500/creating-directories-with-sequential-numbering

Link to comment

Hi - Not sure if this is the right place to post this but I need to be able to run a script which stops my plex docker at say 3am in the morning and then restarts it straight away. The reason I want to do this is that for some reason Plex will be using 100% cpu on a single core for no reason and im currently manually restarting the docker and CPU usage drops.

 

Is this possible using this plugin and if so would appreciate some help in what I need to include within the script (I'm a novice and have no idea where to start)

Link to comment
  • 2 weeks later...
On 1/8/2024 at 5:57 PM, kizer said:

 

Don't know if this will help you much, but its an idea. 

https://unix.stackexchange.com/questions/468500/creating-directories-with-sequential-numbering

 

Thanks, but my need was much simpler.  In the first line of the script I put the following which generates a random number between the applicable season range...

# GENERATE RANDOM SEASON NUMBER
season=$((RANDOM % (1969 - 1929 + 1) + 1929))

 

Then I modify the copy line to read...

# ADD CONTENT TO PRODUCTION SERVER
cp -R /mnt/user/"Television- All Media"/"Looney Tunes (1929)"/"Season $season" /mnt/user/"Television- Media Server"/"Looney Tunes (1929)"

 

Been working like a charm.  Each week it adds a different random season.  There are quite a few use cases for this, but because there are like 40 seasons of this show, I can change it each week (new in Monday, old out Sunday) so you get a random classic cartoon in your television shuffle.

Link to comment
On 1/10/2024 at 9:15 PM, frodr said:

I was just Safari having a hick up. Strange, because it worked on the other server.

Same here with two different servers. But if i try another browser (Opera) it works.

So it must be an issue on Safari's side.

Link to comment
  • 2 weeks later...

I'm currently having issues with this plugin that I can not seem to find out whatsoever.

I'm making a script, set a schedule, clicking apply, nothing happens. 

I've made a script to restart a game docker every other hour on CA User Scripts. I've set the Cron schedule to "0 */2 * * *" also.

Pressing apply does not start the schedule or do anything. I've tried uninstalling the plugin and reinstalling. I've tried on four separate browsers that do not have any form of modification to them at all nor adblockers. (Chrome, Brave, Opera and Edge). I am using the webGUI for reference.

I'm on the most recent stable release of UNRAID, also.

image.png?ex=65cfc9b3&is=65bd54b3&hm=123

image.png?ex=65cfc9b3&is=65bd54b3&hm=ba3

 

The above is script and the information. I can run script and tell it to 'run in background' and it works. But as soon as I leave the page (Clicking Apply then Done), it does not save the custom scheduling at all or anything. I've tried clicking apply, and do not get the notification that others get. Mind you this is the first time I've ever made a script in this Plugin because I hadn't needed to otherwise, so I've never just 'had it work' before in the past and all of a sudden it don't work. 


Here is a picture of someone sending me their view of what happens when they add it. I do not get this at all. It just straight up doesn't work.

image.png?ex=65cfcc30&is=65bd5730&hm=8e0

So I am at a loss. Any help is appreciated or alternatives. 

Edited by StabbyMeowkins
Link to comment

The above issue

On 2/2/2024 at 3:19 PM, StabbyMeowkins said:

I'm currently having issues with this plugin that I can not seem to find out whatsoever.

I'm making a script, set a schedule, clicking apply, nothing happens. 

I've made a script to restart a game docker every other hour on CA User Scripts. I've set the Cron schedule to "0 */2 * * *" also.

Pressing apply does not start the schedule or do anything. I've tried uninstalling the plugin and reinstalling. I've tried on four separate browsers that do not have any form of modification to them at all nor adblockers. (Chrome, Brave, Opera and Edge). I am using the webGUI for reference.

I'm on the most recent stable release of UNRAID, also.

image.png?ex=65cfc9b3&is=65bd54b3&hm=123

image.png?ex=65cfc9b3&is=65bd54b3&hm=ba3

 

The above is script and the information. I can run script and tell it to 'run in background' and it works. But as soon as I leave the page (Clicking Apply then Done), it does not save the custom scheduling at all or anything. I've tried clicking apply, and do not get the notification that others get. Mind you this is the first time I've ever made a script in this Plugin because I hadn't needed to otherwise, so I've never just 'had it work' before in the past and all of a sudden it don't work. 


Here is a picture of someone sending me their view of what happens when they add it. I do not get this at all. It just straight up doesn't work.

image.png?ex=65cfcc30&is=65bd5730&hm=8e0

So I am at a loss. Any help is appreciated or alternatives. 

The above issue was fixed. There was an issue with a script that was made on accident prior to this issue, that broke the entire ability to use the plugin in general.

 

Naming the script with the $ sign, completely disabled the ability to use the apply command in the menu, not allowing you to apply the schedule. 

I had to manually delete the script folder to remove it, before it would work again. Not sure what caused the naming of the script to cause the entire menu to break and refusing the webGUI to work correctly on that page. I was informed to make my post here, as to possibly prevent a miss-type like this from causing this kind of issue. (I could not manually delete the script named with the $ in it either, like I could with other scripts.)

Shout out to @Kilrah and @DiscoverIt for helping me find the solution to this problem.

adasdasdas.webp

Link to comment
On 1/9/2024 at 9:05 AM, ilovetea said:

Hi - Not sure if this is the right place to post this but I need to be able to run a script which stops my plex docker at say 3am in the morning and then restarts it straight away. The reason I want to do this is that for some reason Plex will be using 100% cpu on a single core for no reason and im currently manually restarting the docker and CPU usage drops.

 

Is this possible using this plugin and if so would appreciate some help in what I need to include within the script (I'm a novice and have no idea where to start)

Hi, not sure if you still need help, but try running:

docker restart plex

...in the root shell window in unraid. If this works, add it to a script, and you're done.

  • Like 1
Link to comment

I can see from this thread that the plugin has been around a long time. But I'm new to UnRAID (set up a couple of months ago), but just got round to trying to use this. Just want to say a big thanks to the dev, such a simple (from and end user point of view, no idea how complex the backend is) but effective tool!

 

Donation of thanks sent 🙂

Link to comment

 

35 minutes ago, Kilrah said:

/tmp/user.scripts, i.e. in RAM.

 

Thanks for the reply. 


Weird since running the rclone script GBs of

data is slowly getting written to the cache with nothing else new running to cause the issue.

 

rclone is writing data directly to the array skipping cache. So I am confused. 

 

I will try looking at that folder again. When I checked I couldn’t access any logs will it be in the running folder?

Link to comment

I'm currently having an issue where I am unable to see the "logs" button in the web gui.

 

I've searched the forum and can see example images where the logs button should be, but for some reason I can't see it.

 

1847776481_Screenshot2024-02-13at06_34_21.thumb.png.c55f61bbcba05ed94ec1fb5722ce91c3.png

 

Get the same result in Chrome and Safari. Plugin is up to date and I'm on Unraid 6.12.6

 

I am new to unraid, so might be making a simple mistake. Any help greatly appreciated.

Link to comment
10 minutes ago, Fellini70 said:

I'm currently having an issue where I am unable to see the "logs" button in the web gui.

 

I've searched the forum and can see example images where the logs button should be, but for some reason I can't see it.

 

1847776481_Screenshot2024-02-13at06_34_21.thumb.png.c55f61bbcba05ed94ec1fb5722ce91c3.png

 

Get the same result in Chrome and Safari. Plugin is up to date and I'm on Unraid 6.12.6

 

I am new to unraid, so might be making a simple mistake. Any help greatly appreciated.

Have you ran the scripts in background? No schedule so they are not running.

Link to comment
26 minutes ago, SimonF said:

Have you ran the scripts in background? No schedule so they are not running.

 

Ah ok. I ran the scripts using the "run now" option as a test, before setting up a schedule and I wanted to check the log from that.

I'll set it up to run as a schedule and then see if that gives me the log buttons.

Thank you.

Link to comment
2 hours ago, Fellini70 said:

I ran the scripts using the "run now" option as a test,

I assume you mean the "Run Script" option to run it in the foreground?   If so the log is the contents (if any) of the window that then opens.  If nothing appears there you should not expect anything to appear in the log.

Link to comment
  • 2 weeks later...

Hello,

 

I've implemented user scripts in Unraid to automate folder synchronization with Rclone according to a custom schedule. The scripts work effectively, syncing in the background as intended. However, this success comes at a cost: my internet connection, which has limited bandwidth, becomes virtually unusable during sync operations.

 

To address this, I attempted to create additional scripts to terminate the Rclone sync at scheduled intervals, aiming to restrict internet downtime to nighttime hours. I used the commands

kill $(ps aux | grep '[r]clone' | awk '{print $2}')

 and

killall -9 rclone

both of which execute successfully in the console but fail to work when executed via user scripts. The challenge arises because the process ID (PID) of Rclone changes with each execution, rendering other methods ineffective.

 

I'm seeking advice on how to dynamically terminate a background process, initiated by a user script, using another scheduled user script. Any insights or solutions to this problem would be greatly appreciated.

 

Thank you.

 

EDIT:

Solved by using this really simple but effective rclone flag: --max-duration=TIME

For me "4h" marks was the sweet spot. Hope to help someone else in here!

Edited by luca7
Link to comment

May I issue another feature request here?

 

Please add a button "Delete all log files" at the bottom of the User Scripts page - beside "Add script" etc

 

If hit, this would delete all logs of user scripts and - if needed - would refresh that page.

 

Why? If you have more than 1-3 User Scripts, possibly over 40 like me, it's sometimes neccessary to see what script did run recently.

 

Thanks for listening.

 

Edited by hawihoney
Link to comment
59 minutes ago, hawihoney said:

it's sometimes neccessary to see what script did run recently.

may add another script like, will sort the last finished actions ... ;)

 

-ltr will change from old > new 

root@AlsServerII:~# ls -lt /tmp/user.scripts/finished/
total 40
-rw-r--r-- 1 root root 8 Feb 26 07:09 CF_DNS_Updater
-rw-r--r-- 1 root root 8 Feb 26 07:09 Fan_Control_CPU
-rw-r--r-- 1 root root 8 Feb 26 07:08 Fan_Control_HDD
-rw-r--r-- 1 root root 8 Feb 26 07:00 Avidemux_TVH_Trigger
-rw-r--r-- 1 root root 8 Feb 26 07:00 Calibre_Web_Import
-rw-r--r-- 1 root root 8 Feb 26 04:55 luckybackup_restart
-rw-r--r-- 1 root root 8 Feb 26 03:13 TVHeadend_IPTV_update
-rw-r--r-- 1 root root 8 Feb 26 01:00 speedtest_ookla
-rw-r--r-- 1 root root 8 Feb 25 23:15 Encode
-rw-r--r-- 1 root root 8 Feb 25 07:36 Backup_Media
---
root@AlsServerII:~# ls -ltr /tmp/user.scripts/finished/
total 40
-rw-r--r-- 1 root root 8 Feb 25 07:36 Backup_Media
-rw-r--r-- 1 root root 8 Feb 25 23:15 Encode
-rw-r--r-- 1 root root 8 Feb 26 01:00 speedtest_ookla
-rw-r--r-- 1 root root 8 Feb 26 03:13 TVHeadend_IPTV_update
-rw-r--r-- 1 root root 8 Feb 26 04:55 luckybackup_restart
-rw-r--r-- 1 root root 8 Feb 26 07:00 Calibre_Web_Import
-rw-r--r-- 1 root root 8 Feb 26 07:00 Avidemux_TVH_Trigger
-rw-r--r-- 1 root root 8 Feb 26 07:08 Fan_Control_HDD
-rw-r--r-- 1 root root 8 Feb 26 07:09 Fan_Control_CPU
-rw-r--r-- 1 root root 8 Feb 26 07:09 CF_DNS_Updater
root@AlsServerII:~#

 

  • Thanks 1
Link to comment
6 minutes ago, alturismo said:

may add another script like, will sort the last finished actions

 

I would like to see that at the source - at the User Scripts page itself. With your output I have to switch around between page and output. Thanks anyway.

 

But you create an idea to delete the logs myself - with a User Script ;-) Just need a way to refresh the page then ...

 

This is one half of my User Scripts page - just to get an idea what I'm talking about:

 

image.thumb.png.db3c2679b1bf89478cff26e18aa6be8e.png

Edited by hawihoney
  • Like 1
Link to comment
root@Odin:~# /usr/local/emhttp/plugins/user.scripts/startSchedule.php hourly
bash: /usr/local/emhttp/plugins/user.scripts/startSchedule.php: Permission denied

root@Odin:~# php /usr/local/emhttp/plugins/user.scripts/startSchedule.php hourly
/usr/local/emhttp/plugins/user.scripts/backgroundScript.sh "/tmp/user.scripts/tmpScripts/dynu_updater_hourly/script" >/dev/null 2>&1/usr/local/emhttp/plugins/user.scripts/backgroundScript.sh "/tmp/user.scripts/tmpScripts/pfsense_firewall/script" >/dev/null 2>&1

 

Noticed that I got a permission error in the logs from the User Scripts plugin, it looks like Unraid does not accept the #!/usr/bin/php anymore. I had to add "php" in front of the startSchedule.php in the crontab file to make it work. Can someone test this, I wanna know if it's just my system or a bug/glitch..

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.