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

6 minutes ago, itimpi said:

If you run your own scripts directly from the flash drive then you have to do something to get them to run correctly.

So appending the /bin/bash like Squid says before the path to the script is sufficient? I'm not running the script directly, I'm running them from another user script using the at now technique.

 

I have a bunch of conditional startup scripts that take care of timing of various VM and container launches, since Unraid doesn't provide a way of managing that sort of thing in the GUI.

 

All this is on my 6.7 box, I haven't played around with it on my test boxes yet, but I want to make sure all my ducks are in a row before I apply 6.8.

 

I'm hoping instead of making me do all the testing and validation work, you guys will just tell me how to make it work and I can be lazy. 😁

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

  • Author
2 minutes ago, jonathanm said:

appending

prepending ;) 

 

2 minutes ago, jonathanm said:

is sufficient?

Yes

 

3 minutes ago, jonathanm said:

I'm not running the script directly, I'm running them from another user script using the at now technique.

You actually are running it directly (via the user script)

  • Author
5 minutes ago, jonathanm said:

I can be lazy.

👍

When I click abort scripts it doesnt kill the script from running. Any ideas? Or how to troubleshoot ?

  • Author

Any long running commands will get aborted after they are finished.   I've tried many ways of terminating, and I keep running into the same problem.   I cant kill the PID of any long ru  ing command (rsync)

Ok, well its more of me backing up to b2. There is 150 GB to go. So I only want it going at night. I have to find process then kill pid.

 

Unless you have easy way to find the pid? AKA search for pid including name rclone

  • 2 weeks later...

Anyway to figure out why a script decided not to run?

 

This script didn't run today even though it should have:

 

image.thumb.png.6cc878974288b8c87c0e4afa3fd1564c.png

 

 

looking for a bit of scripting help...

 

I am trying to fetch a TV Guide (xml file) that is around 40Mb. The server is unreliable.

 

using this:

curl -L --limit-rate 200K "http://provider.url/epg?username=un&password=pw" --speed-time 15 --speed-limit 1000 -o /mnt/user/appdata/tvheadend/data/cronIPTV_EPG.xml


I have run this multiple times my so I know the syntax is OK. but about 3 in 5 fail!!!

 

output:

curl: (28) Operation too slow. Less than 1000 bytes/sec transferred the last 15 seconds

 

How do I wrap this command in a loop so that it will try 10 times if it falls over with the "operation too slow" error?

 

 

 

 

 

Hello,

I usually use user script for various backup tasks.

For the need of my home automation system i have to run a python script which is intended to listen push on a port.

The script can be found here.

I have nerdpack plugin installed. When i launch the script i have the following error.

Quote

Script location: /tmp/user.scripts/tmpScripts/Bridge_Jeedom_InfluxDB.py/script
Note that closing this window will abort the execution of this script
Traceback (most recent call last):
File "/tmp/user.scripts/tmpScripts/Bridge_Jeedom_InfluxDB.py/script", line 5, in
from http.server import BaseHTTPRequestHandler, HTTPServer
ImportError: No module named http.server

How can i install this module ? I thought it was included.

Can I launch python script with user script ?

How can i make the script running in background ? It needs to listen to push events.

I think i solved my problem.

i had to change the first line

from

#!/usr/bin/python

to

#!/usr/bin/python3

I also had to install influxdb in a shell window:

pip3 install influxdb

Now i'm waiting for the first push to come.

If i understand right the script has to be lauched with "&" at the end off the command line in order to run without the window opened.

My bad the "run in background" button is huge but i had not seen it.

So i started the script with run un background. I also sheduled a run at array startup

 

With the changes to flash security in 6.8 should I move my custom scripts run via this plugin to a location other than flash? Just want to be sure I’ll still be able to run, edit and create new scripts if the scripts folder is still on flash.

As long as you do the editing and running via the User Scripts plugin then there is no problem as it handles this correctly for the new security settings.

Is it possible to have your user script log to its own logfile?

  • Author
10 hours ago, Tuumke said:

Is it possible to have your user script log to its own logfile?

All scripts log to their own log file which can be viewed / downloaded

  • 2 weeks later...

I'm trying to run a python script every minute with this plugin but I cannot get it to work.

I created a new entry, set scheduling to custom with `* * * * * *` as expression. The content of the script is

#!/bin/bash
/usr/bin/python3.7 /mnt/user/walzen/nzbget_download_rate.py

Running manually (clicking on "Run Script" or "Run in Background") works perfectly fine but for some reason it doesn't execute automatically. I have other cron jobs (bash scripts) that are working normally.

  • Author
8 minutes ago, FunnyPocketBook said:

`* * * * * *`

What is the expression your using?  Because it should only be 5 *, not 6

1 hour ago, Squid said:

What is the expression your using?  Because it should only be 5 *, not 6

Oh my god, I'm such an idiot... Thanks a lot! I spent more than 4 hours trying absolutely everything and didn't even think of checking my expression

  • 2 weeks later...

So I was using User Scripts as normal, but after manually running and cancelling a script the page now seems to be broken.

 

This is all that is shown.  "Appdata Backup" was one of my scripts but the description appears to be the html for the entire page.

US.PNG.33190a81512f36455eb0be49057e1636.PNG

 

I tried uninstalling and reinstalling the plugin without any change.  I've also checked with another browser with the same result, so it doesn't appear to be a browser cache issue.  How would I fix this?

  • Author
1 hour ago, Xe138 said:

So I was using User Scripts as normal, but after manually running and cancelling a script the page now seems to be broken.

 

This is all that is shown.  "Appdata Backup" was one of my scripts but the description appears to be the html for the entire page.

US.PNG.33190a81512f36455eb0be49057e1636.PNG

 

I tried uninstalling and reinstalling the plugin without any change.  I've also checked with another browser with the same result, so it doesn't appear to be a browser cache issue.  How would I fix this?

Not much suggestion on this fine and glorious night other than a reboot.   No idea atm what went went  wrong here.   

 

But, do there happen to be anything luke quotes in the name of the script?

I want to use a script to run a rsync command, but I also want to run this from a screen, so I can check the progress at any time with screen -r. I have several backup scripts for each share that I want to backup.

 

I'm having some issue getting screen to work. This is how the script looks now:

#!/bin/bash

export SCREENDIR=/root/.screen
screen -dmS rsyncdms 

echo "Job '[job name]' started"

rsync [with parameters etc]

/usr/local/emhttp/webGui/scripts/notify -s "Job '[job name]' finished at $(date '+%Y-%m-%d %H:%M')"

So it needs to do 3 things (echo, rsync and notify). When I run the script from the User Scripts page with the Run Script button, it works perfectly. But when I run it in the background and then try to view the status with 'screen -r' in a terminal, I just get a blank terminal with a prompt. I read it's because you need to put something immediately behind the 'screen -dmS rsyncdms' command, but then it still doesn't work.

 

How can I get these 3 things to be executed in order, all within its own screen session? I saw another post where someone made a new user script and within it called the .sh file, but I want to integrate the screen function within the backup script itself, if possible.

13 hours ago, Squid said:

Not much suggestion on this fine and glorious night other than a reboot.   No idea atm what went went  wrong here.   

 

But, do there happen to be anything luke quotes in the name of the script?

I found the problem.  Somehow the description for the script was saved with an html tag in it.

<textarea id="newDescdescAppdataBackup" cols="40" rows="5">Backup of appdata to array

 

Does someone got autossh to work?
My Problem is that it works in a normal ssh session but if i try to start it through the user scripts plugin it wont work.
Do I have to set some special env variable? I tried to copy some of the env variables from another session.
This is my script ATM the first run always stucks at the end and wont terminate and if i run it a second time it runs and terminates but the autossh processes aren't started

#!/bin/bash
SHELL=/bin/bash
LESS=-RM
G_BROKEN_FILENAMES=1
HOSTNAME=Tower
PWD=/root
LOGNAME=root
MANPATH=/usr/local/man:/usr/man
HOME=/root
LANG=en_US.UTF-8
TERM=linux
G_FILENAME_ENCODING=@locale
LESSOPEN=|lesspipe.sh %s
USER=root
NCURSES_NO_UTF8_ACS=1
SHLVL=1
INPUTRC=/etc/inputrc
NODE_PATH=/usr/lib64/node_modules
LC_COLLATE=C
HUSHLOGIN=FALSE
PATH=.:/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin
HZ=100
env
if [ -f /usr/bin/autossh ]
then
echo "already installed. Trying to start sessions now"
else
echo "not installed. Installing..."
wget https://packages.slackonly.com/pub/packages/14.2-x86_64/network/autossh/autossh-1.4g-x86_64-1_slonly.txz
installpkg autossh-1.4g-x86_64-1_slonly.txz
echo "starting Sessions..."
fi
sleep 5
autossh -M 21010 -R :14002:0.0.0.0:14002 -N -f -o "UserKnownHostsFile=/dev/null" -o "StrictHostKeyChecking=no" -i /mnt/user/Private/sshKeysForAutossh/id_ed25519 [email protected]
autossh -M 21030 -R :14003:0.0.0.0:14002 -N -f -o "UserKnownHostsFile=/dev/null" -o "StrictHostKeyChecking=no" -i /mnt/user/Private/sshKeysForAutossh/id_ed25519 [email protected]
autossh -M 21020 -R :32400:0.0.0.0:32400 -N -f -o "UserKnownHostsFile=/dev/null" -o "StrictHostKeyChecking=no" -i /mnt/user/Private/sshKeysForAutossh/id_ed25519 [email protected]
echo "all started"
exit 0

okay I did solve it by myself a simple sudo -u root was necessary in front of each autossh command

Edited by unraidnh
solved

I currently run two scripts that I'd like to combine into one.  They check to see if my cache disk has got to a certain amount of % used

 

- if it's less than a certain amount it moves files that I don't need on the cache to the array so that files I want on the cache can stay on for longer

- if it's over a certain amount then it starts the mover (I've disabled the scheduled mover)

 

Here's the first script:

 

#!/usr/bin/php

<?PHP

$min = 70;
$max = 90;
$moveAt = 90;

$diskTotal = disk_total_space("/mnt/cache");
$diskFree = disk_free_space("/mnt/cache");
$percentUsed = ($diskTotal - $diskFree) / $diskTotal * 100;

if ( $percentUsed > $moveAt ) {
  $my_string = 'Starting mover';
  echo $my_string;
  echo "<br>";
  exec("/usr/local/sbin/mover");
} else {
    $my_string = 'Not running mover';
	echo $my_string;
	echo "<br>";
}

if (($min <= $percentUsed) and ($percentUsed <= $max)) {
  $my_string2 = 'starting diskmv_all';
  echo $my_string2;
  echo "<br>";
  echo "<br>";
  exec("bash /boot/config/plugins/user.scripts/scripts/diskmv_all/script");
} else {
    $my_string = 'Not running diskmv_all';
	echo $my_string;
	echo "<br>";
}
?>

and the second that runs the diskmv script:

#!/bin/bash

#######  Check if script already running  ##########

echo "$(date "+%d.%m.%Y %T") INFO: Creating Tracker file."
if [[ -f "/mnt/user/appdata/other/rclone/diskmv_running" ]]; then

echo "$(date "+%d.%m.%Y %T") INFO: Exiting as script already running."

exit

else

touch /mnt/user/appdata/other/rclone/diskmv_running

fi

if [ -f /var/run/mover.pid ]; then
  if ps h `cat /var/run/mover.pid` | grep mover ; then
      echo "$(date "+%d.%m.%Y %T") INFO: mover already running.  Removing Tracker file."
      rm /mnt/user/appdata/other/rclone/diskmv_running
      exit 0
  fi
fi

# /usr/local/sbin/mdcmd set md_write_method 1

# echo "Turbo write mode now enabled"

echo "$(date "+%d.%m.%Y %T") INFO: moving backup."

bash /boot/config/plugins/user.scripts/scripts/diskmv/script -f -v "/mnt/user/backup" cache disk2

# echo "$(date "+%d.%m.%Y %T") INFO: moving local."

bash /boot/config/plugins/user.scripts/scripts/diskmv/script -f -v "/mnt/user/local/tdrive_vfs/downloads/complete" cache disk1

echo "$(date "+%d.%m.%Y %T") INFO: moving media."

bash /boot/config/plugins/user.scripts/scripts/diskmv/script -f -v "/mnt/user/media/music" cache disk2
bash /boot/config/plugins/user.scripts/scripts/diskmv/script -f -v "/mnt/user/media/other_media/books" cache disk2
bash /boot/config/plugins/user.scripts/scripts/diskmv/script -f -v "/mnt/user/media/other_media/photos" cache disk2
bash /boot/config/plugins/user.scripts/scripts/diskmv/script -f -v "/mnt/user/media/other_media/videos" cache disk2

# /usr/local/sbin/mdcmd set md_write_method 0

# echo "Turbo write mode now disabled"

echo "$(date "+%d.%m.%Y %T") INFO: Removing Tracker file."
rm /mnt/user/appdata/other/rclone/diskmv_running

exit

Is it possible to combine?

 

Thanks in advance

Edited by DZMM

Hi guys

 

Sorry completely useless with coding. 

 

Can anyone help with create a script that will copy the contents of one folder on a share to another shared folder on my Synology Nas please?

 

thanks

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.