Jump to content
Squid

[Plugin] CA User Scripts

907 posts in this topic Last Reply

Recommended Posts

9 minutes ago, Squid said:

Use the notify command built in

 

/usr/local/emhttp/plugins/dynamix/scripts/notify

 

By default that shows a red notification as if there's an error.  Is there a way to manipulate the color displayed?

 

Nvmd, was using the old WebGUI notification.  Thanks.

Edited by IamSpartacus

Share this post


Link to post

Enter it in by itself at the command prompt and you'll see all the options.   You'll either want the type to be normal or warning

Share this post


Link to post
7 minutes ago, Squid said:

Enter it in by itself at the command prompt and you'll see all the options.   You'll either want the type to be normal or warning

and is there a variable one can use to call the name of the script?

Edited by IamSpartacus

Share this post


Link to post
18 minutes ago, IamSpartacus said:

and is there a variable one can use to call the name of the script?

How do you mean?
You can use command substitution if you want the warning to display the output of a command:

WarningText="$(somecommand -someoption somefile.someextension)"
then use "$WarningText" where you would like the output of that command.

Share this post


Link to post

Hello!

 

I'm using this plugin but my script included CJK(Chinese japan, Korea)

 

When saving the script in web ui

the chinese char would be vanish

Is there any bug or somthing?

Thanks!

 

CJK example:

monthchi=("01-一月" "02-二月" "03-三月" "04-四月" "05-五月" "06-六月" "07-七月" "08-八月" "09-九月" "10-十月" "11-十一月" "12-十二月")
would become

monthchi=("01-" "02-" "03-" "04-" "05-" "06-" "07-" "08-" "09-" "10-" "11-" "12-")
 

Share this post


Link to post

Is there any variable that lets you know the original location of the script? Or the only option is to replace:

 

/tmp/user.scripts/tmpScripts/YYY

 

With

 

/boot/config/plugins/user.scripts/scripts/YYY 

Edited by Bruno

Share this post


Link to post
7 hours ago, tah said:

Hello!

 

I'm using this plugin but my script included CJK(Chinese japan, Korea)

 

When saving the script in web ui

the chinese char would be vanish

Is there any bug or somthing?

Thanks!

 

CJK example:

monthchi=("01-一月" "02-二月" "03-三月" "04-四月" "05-五月" "06-六月" "07-七月" "08-八月" "09-九月" "10-十月" "11-十一月" "12-十二月")
would become

monthchi=("01-" "02-" "03-" "04-" "05-" "06-" "07-" "08-" "09-" "10-" "11-" "12-")
 

Due to various problems with people cutting and pasting from the forum, all characters except for ASCII are stripped from the scripts automatically.  You're best saving your script elsewhere and use user.scripts to create a script to call the real one.

Share this post


Link to post
5 hours ago, Bruno said:

Is there any variable that lets you know the original location of the script?

no

Share this post


Link to post

OK, so now all schedules including Array Start and 1st boot only will start in the background.  This does mean that if you have multiple scripts running on the same schedule then they will run concurrently.  If this causes issues, you will have to redo your scripts so that #1 calls #2 calls #3 etc.

Share this post


Link to post
On 2/27/2020 at 10:29 AM, Squid said:

no

 

On 2/27/2020 at 5:25 AM, Bruno said:

Is there any variable that lets you know the original location of the script? Or the only option is to replace:

 

/tmp/user.scripts/tmpScripts/YYY

 

With

 

/boot/config/plugins/user.scripts/scripts/YYY 

Try:


#!/bin/bash

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"

$DIR will then contain the folder the script was ran from.

Share this post


Link to post
15 minutes ago, Xaero said:

 

Try:


#!/bin/bash

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"

 

$DIR will then contain the folder the script was ran from.

He was asking the original location of the script and not where its executed from.   The original location is on the flash.   But its processed and then executed from /tmp

Share this post


Link to post
35 minutes ago, Squid said:

He was asking the original location of the script and not where its executed from.   The original location is on the flash.   But its processed and then executed from /tmp

Oh, rip

Share this post


Link to post
Posted (edited)

Anyone also experiencing instant Firefox tab hang2crash after clicking script log of an in background running script?

This happens when running rsync with quite some stdout.

Currently running UR 6.8.3/ US 2020.02.27 / FF 73.0.1

Edited by 54tgedrg45

Share this post


Link to post
15 minutes ago, 54tgedrg45 said:

Anyone also experiencing instant Firefox tab hang2crash after clicking script log of an in background running script?

This happens when running rsync with quite some stdout.

Currently running UR 6.8.3/ US 2020.02.27 / FF 73.0.1

If the log is insanely long, any browser will choke on it.

Share this post


Link to post
Posted (edited)
22 minutes ago, Squid said:

If the log is insanely long, any browser will choke on it.

If so, is it somehow possible to just capture tail of log for the plugin to display within browser limits?

Edited by 54tgedrg45

Share this post


Link to post

Command prompt

 

Something akin to

tail -f /tmp/user.scripts/tmpScripts/Set permissions on Downloads/log.txt

 

Share this post


Link to post

I have a working script that I'm now trying to run every 2 minutes via cron. I selected the Custom option from the scheduled drop down menu and enter */2 * * * * as the Custom Cron Schedule value and then click on Run In Background. A pop-up window opens telling me the script is running in the background which I then close. I have modified my script temporarily to write entries into the log file every time it runs. I know the script runs once because I see the output in the log file but it but does not run again. My settings do not remain after reboot or even if I navigate away from the User Scripts management page and then come back. I'm not sure how to fix this issue. What am I doing wrong here??

Share this post


Link to post

You don't need to click run in background.  All you have to do is set the cron and hit apply down at the bottom.  As to why it's doing what it's doing no one can answer without seeing the exact script.

Share this post


Link to post
50 minutes ago, Squid said:

You don't need to click run in background.  All you have to do is set the cron and hit apply down at the bottom.  As to why it's doing what it's doing no one can answer without seeing the exact script.

Thanks for the reply. The script was working just fine all I needed was to get it running in cron. I was clicking Run In Background instead of Apply.  Once I used Apply it was loaded into Cron and persistent across a reboot. Everything is working just like I need now. Thank you

Share this post


Link to post

Is #noParity=true working on 6.8.2? My script still runs during parity check so I have to manually abort it. 

Share this post


Link to post

Send me a PM in a week to remind me to look at / fix

Share this post


Link to post

Is there a way to purge or fix this plugin? I did broke it, don't know how, it lands me to a blank page even upon reinstalling it.

Share this post


Link to post

Deleting the contents of /config/plugins/user.scripts on the flash drive followed by an uninstall then a reinstall will set it back to default.   You will however loose your scripts.  If you need to keep your scripts then dont delete the contents of the scripts folder

Share this post


Link to post

Hi, Squid.

The pop-up argument input was fine, but after I upgraded the plugin. It's gone.

Could you review my code?

#!/bin/bash
#description=Here is a housekeeping script. By default just deletes empty timestamp directories. Optionally, it can delete snapshots.
foregroundOnly=true
backgroundOnly=true
#arrayStarted=false
#name= BTRFS cleanup
#argumentDescription="-a purges all snapshots; -i <Comma seperated list of shares> purges the selected shares. example -i Downloads,Test1,Test2 will purge all snapshots for Downloads, Test1, and Test2."
#argumentDefault=-a
shopt -s nullglob

POSITIONAL=()
while [[ $# -gt 0 ]]
do
key="$1"

case $key in
    -i|--include)
    INCLUDE="$2"
    shift # past argument
    shift # past value
    ;;
    -a|--all)
    ALL=YES
    shift
    ;;
    *)    # unknown option
    POSITIONAL+=("$1") # save it in an array for later
    shift # past argument
    ;;
esac
done
set -- "${POSITIONAL[@]}" # restore positional parameters

#Tokenize include list
declare -A includes
for token in ${INCLUDE//,/ }; do
        includes[$token]=1
done

#iterate over all disks on array
for disk in /mnt/disk*[0-9]* ; do
 #iterate over each timestamp
 for timestamp in ${disk}/.snapshots/* ; do
  #iterate over each share in the timestamp
  for snap in $timestamp/* ; do
   if [ -n "${includes[$(basename $snap)]}" ] || [ "$ALL" = "YES" ] ; then
    echo "Purging - $snap"
    btrfs subvolume delete $snap
  fi
  #check for empty timestamp
  if [ ! "$(ls -A $timestamp)" ] ; then
   echo "Purging empty directory - $timestamp"
   rmdir $timestamp
  fi
  done
 done
done

and it's original from 

Thank you so much.

Share this post


Link to post

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.