[Plugin] CA User Scripts


Recommended Posts

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. 😁

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

Link to comment
  • 2 weeks later...

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?

 

 

 

 

 

Link to comment

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.

Link to comment

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

 

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

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

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

Link to comment

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.

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

 

Link to comment

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

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