[Plugin] CA User Scripts


Recommended Posts

On 9/21/2020 at 5:29 PM, Alex.b said:

How can I access to /tmp/user.scripts/ to view full logs ?

 

open unraid terminal (or ssh, etc) and use the "cd" command like so:

cd /tmp/user/scripts/tmpScripts/xxx/

 

be sure to use capitals when necessary. If the script log is short, you can use the "cat" command to view directly in terminal window like so:

cat /tmp/user.scripts/tmpScripts/xxx/xxx.txt

(or if you used the "cd" command to navigate to the directory already, use:)

cat xxx.txt

 

If the log is too long to view its contents entirely in the terminal, you can copy the log to an easier to access location, such as a folder on the array, and open with a notepad app to view the whole log, like so:

cp /tmp/user.scripts/tmpScripts/xxx/xxx.txt /insert/destination/path/here

 

hope this helps

Link to comment
On 9/17/2020 at 4:55 AM, cmarshall85 said:

 

@Derek_ did you ever figure this out? I am having the same issue. When I run lftp, any folders/files it creates are root:root and i need it to be nobody:users. Thanks!

Hiya, sorry it's taken so long to reply. No - i never figured it out. I just accepted it as it was. As someone mentions, you can chown it after operations are complete if that works for your scenario.

Link to comment

Eum, where are the script output logs stored? after execution(of all scripts) I get the trashcan to delete log icon/prompt to delete log of task name, not informing path of log.

How to view them?

No idea where it would be. at flash /logs it shows none.

 

Edit: OK, they can be found at /tmp/user.scripts/tmpScripts/

 

# logfile log.txt

Edited by 54tgedrg45
Link to comment
2 hours ago, 54tgedrg45 said:

Eum, where are the script output logs stored?

There aren't any. The logs are buggy so I used this at the beginning of all my scripts:

# logging
exec > >(tee --append --ignore-interrupts $(dirname ${0})/log.txt) 2>&1

By that all output is twice in the logs, but this was the only solution that worked.

 

And only to inform you. There is another bug. Its not possible to stop scripts although the dashboard claims it. It seems @Squiddid not found the time to correct it. I posted two ways to solve it.

 

Link to comment

User scripts has grown from a quickly bolted together handy but buggy tool into a substantial part of unraid that a lot of users have use for, and it needs and deserves a lot of rework and refactoring and attention to take it to a higher level. 

Edited by jowi
Link to comment

Yes, if i had the expertise. I can do c# .net core etc programming and some minor python, but somehow i think that is not needed here. Also linux is not my thing.

 

If you’re suggesting i am not allowed to comment unless i contribute? F*** you. That is not up to you.

Edited by jowi
Link to comment
5 hours ago, mgutt said:

The logs are buggy

The logs are everything that is output by the script. And there's a download button that grabs them.

 

Other things

 

This is going to come across as a bit bitchy, but I truly don't mean anything by it.

 

This plugin was simply designed to run a quick and dirty script here and there.  It has definitely morphed into something else.  And yes there are issues with

  • Certain script naming will crash the plugin
  • Sub processes spawned off of the initial script have issues being stopped

 

Priorities are everything.  While I do understand and appreciate the comments and suggestions, time doesn't always play along with supporting of code changes (or as probably needed here a complete rewrite of the plugin - which isn't an inconsequential time investment) and/or fixes.

 

My priorities are as follows:

 

  1. CA, application feed, related items.  They trump everything else
  2. Actual real-world work
  3. Fix Common Problems (Any false positives that may pop up as new versions of Unraid are released)
  4. Unraid GUI bug fixes etc
  5. Alexander Keith's
  6. Dogs
  7. Sleep
  8. Family
  9. Doom

(Hopefully the wife doesn't read this ;), but that order does keep me sane)

 

So far as time permitting after all of that, the priorities that I see plugin related (time permitting) are

 

  1. Autoupdate.  I've noticed some oddities that I'm not sure if its a bug or not and need to investigate
  2. Backup / Restore - restart order doesn't match what's been utilized in the docker tab
  3. Cleanup Appdata - needs a big revamp to make it functionally work without probable timeouts happening if/when the deletions take more than 120 seconds
  4. Backup / Restore - Longstanding req to separate the archives by folder, and selectively restore them

This plugin lags behind because it still is 100% functional within its original design considerations.  Problem with it is that the code is ancient, and a rewrite is basically required to bring it into line with everything else, and make it maintainable.

 

Unfortunately due to priority #2, my time is extremely limited until Christmas, and what time I do have may be filled up with priority #5 when the situation may change.

 

I will get to it.  I, like everyone else around here am a volunteer.  In the meantime if anyone has any PRs, then they will get merged after testing.

 

 

 

 

Link to comment
3 hours ago, Squid said:

The logs are everything that is output by the script. And there's a download button that grabs them.

 

No. Does not work. echo "bla" is not logged. No verbose output is logged. Only fatal errors are logged. This is the reason why so many people complain and ask for the "real download" ;)

Link to comment

Hi!
 

Great little plugin, thanks a lot.

 

I have a question though: I want to start a script that runs in background after the disk array starts.

 

This is the content of the script:

 

#!/bin/bash
tail -F "/mnt/cache/appdata/plex/Library/Application Support/Plex Media Server/Logs/Plex Media Server.log" | \
while read line ; do
        echo "$line" | grep "authenticated user"
        if [ $? = 0 ]
        then    
        mdcmd spinup 0    
        mdcmd spinup 1    
        mdcmd spinup 2    
        sleep 30
        fi
done

what it does is it spins up the disks whenever somebody opens plex

 

obviously I want to keep the script running in the background when unraid boots up... is it ok to just start the script with the "At Startup of Array"- option? will it keep running in the background then?

 

thanks

 

MJFox

Link to comment
10 minutes ago, MJFOx said:

This is the content of the script:

Hopefully somebody else can answer your actual question, but as a side thought you could replace...

        mdcmd spinup 0    
        mdcmd spinup 1    
        mdcmd spinup 2

...with...

disks=$(ls /dev/md* | sed "sX/dev/mdXX");
for disknum in $disks; do
    /usr/local/sbin/mdcmd spinup $disknum;
done

I currently run this on a CRON schedule every 10 minutes between 19:00 and 23:00 to speed up Plex.  I'd therefore be interested in your question too, as it's more useful.

  • Like 1
Link to comment
2 hours ago, Cessquill said:

Hopefully somebody else can answer your actual question, but as a side thought you could replace...


        mdcmd spinup 0    
        mdcmd spinup 1    
        mdcmd spinup 2

...with...


disks=$(ls /dev/md* | sed "sX/dev/mdXX");
for disknum in $disks; do
    /usr/local/sbin/mdcmd spinup $disknum;
done

I currently run this on a CRON schedule every 10 minutes between 19:00 and 23:00 to speed up Plex.  I'd therefore be interested in your question too, as it's more useful.

thanks for your suggestion

 

I just tried and tested my script and it works well in the background, I just changed "tail -F " to "tail -n 1 -F " so my script only checks the last line of the log-file

 

give it a try

 

Cheers

 

MJFox

 

 

Link to comment
5 hours ago, MJFOx said:

is it ok to just start the script with the "At Startup of Array"- option? will it keep running in the background then?

Yes, because "tail -F" monitors file changes, it will run forever.

 

But I don't know if it could be killed somehow. Maybe it's better to set it to hourly and execute it atomic. I use this in my scripts:

# make script race condition safe
if [[ -d "/tmp/${0///}" ]] || ! mkdir "/tmp/${0///}"; then
    exit 1
fi
trap 'rmdir "/tmp/${0///}"' EXIT

Explanation: This generates a dir in the temp folder, which is deleted when the script is aborted. If the dir exists it aborts the execution (which prevents executing it twice).

 

And I don't know if it would be a problem to spin up a drive, that is already spinning. Maybe we check the spin status first. I tried to find out which command returns such a status. The only one I found was this:

mdcmd status 1 | grep rdevLastIO

So the complete script would look like this:

# make script race condition safe
if [[ -d "/tmp/${0///}" ]] || ! mkdir "/tmp/${0///}"; then
    exit 1
fi
trap 'rmdir "/tmp/${0///}"' EXIT
# spin up drives on plex user login
tail -F "/mnt/cache/appdata/plex/Library/Application Support/Plex Media Server/Logs/Plex Media Server.log" | \
while read line ; do
    echo "$line" | tail -n 1 -F | grep "authenticated user"
    if [ $? = 0 ]; then
        disk0_status=$(mdcmd status | grep "rdevLastIO.0=" | cut -d '=' -f 2 | tr -d '\n')
        if [[ $disk0_status == "0" ]]; then
            echo "Spin up disk 0"
            mdcmd spinup 0
        fi
        disk1_status=$(mdcmd status | grep "rdevLastIO.1=" | cut -d '=' -f 2 | tr -d '\n')
        if [[ $disk1_status == "0" ]]; then
            echo "Spin up disk 1"
            mdcmd spinup 1
        fi
        disk2_status=$(mdcmd status | grep "rdevLastIO.2=" | cut -d '=' -f 2 | tr -d '\n')
        if [[ $disk2_status == "0" ]]; then
            echo "Spin up disk 2"
            mdcmd spinup 2
        fi
    fi
done

I removed sleep as even if two users log in, it won't spinup twice as it checks the spinning status first.

 

P.S. If disk0 is your parity drive, you don't need to spin it up ;)

Edited by mgutt
Link to comment

I thought about it again. What do you think if we monitor the Plex Container CPU load instead? By that it would work without enabling debugging in Plex, which is needed by the above script. I disabled debugging to avoid permanent writes on my SSD.

 

EDIT: I created a version which monitors the load:

 

Edited by mgutt
Link to comment

I have a VERY basic find+cp script, which works in the web command line, but doesn't, when I want to run it with custom scripts (I just tried it manually)

Any ideas?

#!/bin/bash

find /mnt/user/mini/myfolder/ . -iname '*.mkv'

-exec cp -n {} /mnt/user/mini/myfolder \;

 

When I click Run Script, I get the find results, and "find: './sys/kernel/slab': Input/output error"

 

And the cp can't start with this error in the find 'results'.

 

What am I doing wrong?

Btw i just try to copy files from the subfolders to the main folder. the subfolders will be deleted by the DL client, when seeding is done.

Link to comment
5 hours ago, LSL1337 said:

When I click Run Script, I get the find results, and "find: './sys/kernel/slab': Input/output error"

I wonder that this script works in the terminal as you passed two paths: "mnt/user/mini/myfolder/" and ".". Simply remove the dot. It means "search everywhere starting at the root folder" and when it tries to find something in "/sys/kernel/slab" it will be blocked, which produces the error. Other examples:

https://stackoverflow.com/a/26234223/318765

 

Note: I would write the command in one line as "-exec" is part of the "find" command.

Link to comment

plugin: installing: https://raw.githubusercontent.com/Squidly271/user.scripts/master/plugins/user.scripts.plg
plugin: downloading https://raw.githubusercontent.com/Squidly271/user.scripts/master/plugins/user.scripts.plg
plugin: downloading: https://raw.githubusercontent.com/Squidly271/user.scripts/master/plugins/user.scripts.plg ... failed (Network failure)
plugin: wget: https://raw.githubusercontent.com/Squidly271/user.scripts/master/plugins/user.scripts.plg download failure (Network failure)

Updating Support Links



Finished Installing. If the DONE button did not appear, then you will need to click the red X in the top right corner

how do i fix that ?

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.