[Plugin] CA User Scripts


Recommended Posts

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.

Link to comment

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-")
 

Link to comment
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.

Link to comment

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.

Link to comment
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.

Link to comment
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

Link to comment
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.

Link to comment

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??

Link to comment
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

Link to comment
  • 2 weeks later...

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

Link to comment

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.

Link to comment
On 3/26/2020 at 10:52 AM, Squid said:

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

Once deleted tryed to reinstall it, this happens:

 

image.png.de0cc2c00d934e850b06633287a7e267.png

 

image.thumb.png.d4968da067e842ac08a983b20deb0a53.png

 

Removed and installed again, same behaviour.

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.