Jump to content
Squid

[Plugin] CA User Scripts

704 posts in this topic Last Reply

Recommended Posts

Posted (edited)

So i have a question. I am screwing up some how on the plex script. I wanted to see if anyone had an idea on how to fix this. Any help would be greatly appreciated. Thanks. I it was working perfect in the unraid rc8 and i had problems with the update and had to go backwards to 6.6.7 and now I am getting this.

Screen Shot 2019-05-11 at 11.02.08 AM.png

Edited by acozad1

Share this post


Link to post
1 hour ago, acozad1 said:

So i have a question. I am screwing up some how on the plex script. I wanted to see if anyone had an idea on how to fix this. Any help would be greatly appreciated. Thanks. I it was working perfect in the unraid rc8 and i had problems with the update and had to go backwards to 6.6.7 and now I am getting this.

Screen Shot 2019-05-11 at 11.02.08 AM.png

 

Please don't ask the same question on multiple threads. You didn't even reference the other thread where there was already a discussion going on about your problem. Your problem isn't likely related to this plugin anyway. And you didn't give any more information than you had already given on that other thread, even though you were told there that you hadn't given us enough information.

 

Crossposting has been considered a bad thing on message boards since long before the world wide web. How can we coordinate our responses when there are discussions going on multiple threads. It just wastes time and effort.

 

Please reconsider if you think about doing this again. If you want I will delete your post and mine on this thread, or I can split them from here and put them back on that other thread.

Share this post


Link to post

May 11 21:21:54 Unraid root: error: /plugins/user.scripts/exec.php: wrong csrf_token
May 11 21:21:55 Unraid root: error: /plugins/user.scripts/exec.php: wrong csrf_token
May 11 21:21:56 Unraid root: error: /plugins/user.scripts/exec.php: wrong csrf_token
May 11 21:21:57 Unraid root: error: /plugins/user.scripts/exec.php: wrong csrf_token
May 11 21:21:58 Unraid root: error: /plugins/user.scripts/exec.php: wrong csrf_token
May 11 21:21:59 Unraid root: error: /plugins/user.scripts/exec.php: wrong csrf_token
May 11 21:22:00 Unraid root: error: /plugins/user.scripts/exec.php: wrong csrf_token
May 11 21:22:01 Unraid root: error: /plugins/user.scripts/exec.php: wrong csrf_token
May 11 21:22:02 Unraid root: error: /plugins/user.scripts/exec.php: wrong csrf_token
May 11 21:22:03 Unraid root: error: /plugins/user.scripts/exec.php: wrong csrf_token
May 11 21:22:04 Unraid root: error: /plugins/user.scripts/exec.php: wrong csrf_token
May 11 21:22:05 Unraid root: error: /plugins/user.scripts/exec.php: wrong csrf_token
May 11 21:22:06 Unraid root: error: /plugins/user.scripts/exec.php: wrong csrf_token
May 11 21:22:09 Unraid root: error: /plugins/user.scripts/exec.php: wrong csrf_token
May 11 21:22:10 Unraid root: error: /plugins/user.scripts/exec.php: wrong csrf_token
May 11 21:22:11 Unraid root: error: /plugins/user.scripts/exec.php: wrong csrf_token
May 11 21:22:12 Unraid root: error: /plugins/user.scripts/exec.php: wrong csrf_token
May 11 21:22:13 Unraid root: error: /plugins/user.scripts/exec.php: wrong csrf_token
May 11 21:22:14 Unraid root: error: /plugins/user.scripts/exec.php: wrong csrf_token
May 11 21:22:15 Unraid root: error: /plugins/user.scripts/exec.php: wrong csrf_token
May 11 21:22:16 Unraid root: error: /plugins/user.scripts/exec.php: wrong csrf_token
May 11 21:22:17 Unraid root: error: /plugins/user.scripts/exec.php: wrong csrf_token
May 11 21:22:18 Unraid root: error: /plugins/user.scripts/exec.php: wrong csrf_token
May 11 21:22:19 Unraid root: error: /plugins/user.scripts/exec.php: wrong csrf_token
May 11 21:22:20 Unraid root: error: /plugins/user.scripts/exec.php: wrong csrf_token

Getting this spammed constantly in logs since update to 6.7. Thousands and thousands of entries since last night. Thoughts?

Share this post


Link to post

If I schedule something to be executed on "At Stopping Of Array" - will that make the power down wait for that user script to finish first? I wanted to have an automatic backup sync before powerdown, but since there is no scheduling for "At Power Off" or similar, I was wondering if it would work by just having it run at stop of array, though then it begs the question too; until my script finishes I can't start the array again either?

Share this post


Link to post
51 minutes ago, fsix said:

If I schedule something to be executed on "At Stopping Of Array" - will that make the power down wait for that user script to finish first? I wanted to have an automatic backup sync before powerdown, but since there is no scheduling for "At Power Off" or similar, I was wondering if it would work by just having it run at stop of array, though then it begs the question too; until my script finishes I can't start the array again either?

Correct on all points.  Setting a schedule like that means that the shutdown (or startup) procedure is on hold until the script is finished.  Unless you start another script via the first one that launches in the background

 

echo "the/real/script" | at NOW -m

 

Share this post


Link to post

Thanks! Wonder if there is a better method then to schedule for actual poweroff only then? since I do sometimes stop the array and it could take some time to sync the backup. Your example would immediately exit and schedule it for "now" - so it would make sense only for power on I assume? otherwise it'll just poweroff and abort the script from executing, right?

Share this post


Link to post

There is no "event" for a power down.  And, since your script (presumably) requires the share system to be up and running, then running in the background isn't an option either.

Share this post


Link to post

Oh, that does make sense actually, then just to clarify: if I set it to the "array off" schedule, it'll finish the script first before actually turning off the array?

Share this post


Link to post

I have a script that, when run in a terminal window, behaves itself. When I try and run it from the user scripts plugin it seems to fail and show some output that doesn't appear when run from a terminal window. Just to add to my confusion I can run the script in a terminal window for the docker in question and it works perfectly.

Here's an example of the output I get from the user scripts plugin...

 

script location: /tmp/user.scripts/tmpScripts/Get guide/script
Note that closing this window will abort the execution of this script
the input device is not a TTY
Will not apply HSTS. The HSTS database must be a regular and non-world-writable file.
ERROR: could not open HSTS store at '//.wget-hsts'. HSTS will be disabled.
--2019-05-27 11:58:51-- http://xxxxx.xxxxx.xx/xmltv.php?username=xxxxxxxx&password=xxxxxxxx
Resolving xxxxx.xxxxx.xx (xxxxx.xxxxx.xx)... 12.34.13.12
Connecting to xxxxx.xxxxx.xx (xxxxx.xxxxx.xx)|12.34.13.12|:80... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: http://xxxxx.xxxxx.xx/xmltv.php?username=xxxxxxxx&password=xxxxxxxx [following]
--2019-05-27 11:58:51-- http://xxxxx.xxxxx.xx/xmltv.php?username=xxxxxxxx&password=xxxxxxxx
Resolving (xxxxx.xxxx.xxx)... 123.456.789.123
Connecting to xxxxx.xxxx.xxx (xxxxx.xxxx.xxx)|123.456.789.123|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [application/xml]
Saving to: '/usr/bin/epg.xml'

0K .......... .......... .......... .......... .......... 155K
50K .......... .......... .......... .......... .......... 328K
100K .......... .......... .......... .......... .......... 3.74M
150K .......... .......... .......... .......... .......... 27.8M
200K .......... .......... .......... .......... .......... 305K
250K .......... .......... .......... .......... .......... 35.7M
300K .......... .......... .......... .......... .......... 37.7M
350K .......... .......... .......... .......... .......... 37.5M
400K .......... .......... .......... .......... .......... 357K
450K .......... .......... .......... .......... .......... 4.05M
500K .......... .......... .......... .......... .......... 6.57M
550K .......... .......... .......... .......... .......... 38.8M
600K .......... .......... .......... .......... .......... 40.8M
650K .......... .......... .......... .......... .......... 40.8M
700K .......... .......... .......... .......... .......... 11.9M
750K .......... .......... .......... .......... .......... 32.2M
800K .......... .......... .......... .......... .......... 40.7M
850K .......... .......... .......... .......... .......... 390K
900K .......... .......... .......... .......... .......... 8.13M
950K .......... .......... .......... .......... .......... 10.5M
1000K .......... .......... .......... .......... .......... 4.33M
1050K .......... .......... .......... .......... .......... 28.2M
1100K .......... .......... .......... .......... .......... 8.48M
1150K .......... .......... .......... .......... .......... 24.1M
1200K .......... .......... .......... .......... .......... 36.2M
1250K .......... .......... .......... .......... .......... 39.8M
1300K .......... .......... .......... .......... .......... 37.4M
1350K .......... .......... .......... .......... .......... 39.3M
1400K .......... .......... .......... .......... .......... 39.7M
1450K .......... .......... .......... .......... .......... 36.8M
1500K .......... .......... .......... .......... .......... 38.4M
1550K .......... .......... .......... .......... .......... 38.1M
1600K .......... .......... .......... .......... .......... 40.1M
1650K .......... .......... .......... .......... .......... 44.4M
1700K .......... .......... .......... .......... .......... 42.6M
1750K .......... .......... .......... .......... .......... 458K
1800K .......... .......... .......... .......... .......... 3.11M
1850K .......... .......... .......... .......... .......... 37.2M
1900K .......... .......... .......... .......... .......... 43.7M
1950K .......... .......... .......... .......... .......... 24.7M
2000K .......... .......... .......... .......... .......... 6.73M
2050K .......... .......... .......... .......... .......... 9.95M
2100K .......... .......... .......... .......... .......... 38.7M
2150K .......... .......... .......... .......... .......... 37.1M
2200K .......... .......... .......... .......... .......... 45.6M
2250K .......... .......... .......... .......... .......... 38.6M
2300K .......... .......... .......... .......... .......... 23.4M
2350K .......... .......... .......... .......... .......... 37.3M
2400K .......... .......... .......... .......... .......... 12.7M
2450K .......... .......... .......... .......... .......... 41.1M
2500K .......... .......... .......... .......... .......... 41.0M
2550K .......... .......... .......... .......... .......... 37.9M
2600K .......... .......... .......... .......... .......... 38.3M
2650K .......... .......... .......... .......... .......... 39.8M
2700K .......... .......... .......... .......... .......... 37.3M
2750K .......... .......... .......... .......... .......... 37.8M
2800K .......... .......... .......... .......... .......... 39.0M
2850K .......... .......... .......... .......... .......... 35.7M
2900K .......... .......... .......... .......... .......... 31.9M
2950K .......... .......... .......... .......... .......... 48.0M
3000K .......... .......... .......... .......... .......... 36.4M
3050K .......... .......... .......... .......... .......... 38.6M
3100K .......... .......... .......... .......... .......... 55.0M
3150K .......... .......... .......... .......... .......... 37.7M
3200K .......... .......... .......... .......... .......... 42.2M
3250K .......... .......... .......... .......... .......... 32.2M
3300K .......... .......... .......... .......... .......... 32.2M
3350K .......... .......... .......... .......... .......... 29.7M
3400K .......... .......... .......... .......... .......... 263K
3450K .......... .......... .......... .......... .......... 292M
3500K .......... .......... .......... .......... .......... 362M
3550K .......... .......... .......... .......... .......... 167M
3600K .......... .......... .......... .......... .......... 223M
3650K .......... .......... .......... .......... .......... 421M
3700K .......... .......... .......... .......... .......... 350M
3750K .......... .......... .......... .......... .......... 385M
3800K .......... .......... .......... .......... .......... 336M
3850K .......... .......... .......... .......... .......... 361M
3900K .......... .......... .......... .......... .......... 430M
3950K .......... .......... .......... .......... .......... 383M
4000K .......... .......... .......... .......... .......... 322M
4050K .......... .......... .......... .......... .......... 422M
4100K .......... .......... .......... .......... .......... 357M
4150K .......... .......... .......... .......... .......... 413M
4200K .......... .......... .......... .......... .......... 340M
4250K .......... .......... .......... .......... .......... 271M
4300K .......... .......... .......... .......... .......... 415M
4350K .......... .......... .......... .......... .......... 408M
4400K .......... .......... .......... .......... .......... 393M
4450K .......... .......... .......... .......... .......... 480M
4500K .......... .......... .......... .......... .......... 397M
4550K .......... .......... .......... .......... .......... 500M
4600K .......... .......... .......... .......... .......... 400M
4650K .......... .......... .......... .......... .......... 317M
4700K .......... .......... .......... .......... .......... 470M
4750K .......... .......... .......... .......... .......... 467M
4800K .......... .......... .......... .......... .......... 400M
4850K .......... .......... .......... .......... .......... 394M
4900K .......... .......... .......... .......... .......... 318M
4950K .......... .......... .......... .......... .......... 494M
5000K .......... .......... .......... .......... .......... 334M
5050K .......... .......... .......... .......... .......... 416M
5100K .......... .......... .......... .......... .......... 422K
5150K .......... .......... .......... .......... .......... 292M
5200K .......... .......... .......... .......... .......... 405M
5250K .......... .......... .......... .......... .......... 11.0M
5300K .......... .......... .......... .......... .......... 181M
5350K .......... .......... .......... .......... .......... 331M
5400K .......... .......... .......... .......... .......... 9.42M
5450K .......... .......... .......... .......... .......... 308M
5500K .......... .......... .......... .......... .......... 308M
5550K .......... .......... .......... .......... .......... 338M
5600K .......... .......... .......... .......... .......... 402M
5650K .......... .......... .......... .......... .......... 302M
5700K .......... .......... .......... .......... .......... 9.55M
5750K .......... .......... .......... .......... .......... 357M
5800K .......... .......... .......... .......... .......... 10.5M
5850K .......... .......... .......... .......... .......... 178M
5900K .......... .......... .......... .......... .......... 293M
5950K .......... .......... .......... .......... .......... 322M
6000K .......... .......... .......... .......... .......... 302M
6050K .......... .......... .......... .......... .......... 230M
6100K .......... .......... .......... .......... .......... 10.5M
6150K .......... .......... .......... .......... .......... 274M
6200K .......... .......... .......... .......... .......... 321M
6250K .......... .......... .......... .......... .......... 10.2M
6300K .......... .......... .......... .......... .......... 367M
6350K .......... .......... .......... .......... .......... 371M
6400K .......... .......... .......... .......... .......... 301M
6450K .......... .......... .......... .......... .......... 301M
6500K .......... .......... .......... .......... .......... 383M
6550K .......... .......... .......... .......... .......... 10.5M
6600K .......... .......... .......... .......... .......... 479M
6650K .......... .......... .......... .......... .......... 361M
6700K .......... .......... .......... .......... .......... 436M
6750K .......... .......... .......... .......... .......... 372M
6800K .......... .......... .......... .......... .......... 395M
6850K .......... .......... .......... .......... .......... 297M
6900K .......... .......... .......... .......... .......... 260M
6950K .......... .......... .......... .......... .......... 361M
7000K .......... .......... .......... .......... .......... 299M
7050K .......... .......... .......... .......... .......... 317M
7100K .......... .......... .......... .......... .......... 441M
7150K .......... .......... .......... .......... .......... 496M
7200K .......... .......... .......... .......... .......... 457M
7250K .......... .......... .......... .......... .......... 322M
7300K .......... .......... .......... .......... .......... 452M
7350K .......... .......... .......... .......... .......... 497M
7400K .......... .. 378M=1.5s

2019-05-27 11:58:53 (4.73 MB/s) - '/usr/bin/epg.xml' saved [7590637]

 

 

So when I run the exact same script from a terminal window I see none of the TTY and HSTS messages ...and it appears to run perfectly....what am I missing?

Thanks for looking!

 

Share this post


Link to post
Just now, Richie12a said:

the input device is not a TTY

Because there is no TTY input (keyboard) on the popup

 

1 minute ago, Richie12a said:

ERROR: could not open HSTS store at '//.wget-hsts'. HSTS will be disabled.

maybe you'll have to cd into the appropriate directory in your script.

 

 

Share this post


Link to post

  28 minutes ago, Richie12a said:

ERROR: could not open HSTS store at '//.wget-hsts'. HSTS will be disabled.

maybe you'll have to cd into the appropriate directory in your script.

 

Thanks for looking!

Unfortunately I have no idea what I would need to do to remedy this....

Share this post


Link to post

I have set up a custom schedule (* * * * *) to run my script every minute. In this script I got a loop, which will make the script run until xx:xx:55 and then exit out of it. But after that, the script isnt started up again at the next full minute, it will have to wait 65 seconds, and then it will get started on the next full minute again. If I set it to end at xx:xx:50 it will only have to wait 10 seconds to get started again...

 

Is it on purpose scripts can't get started again only 5 seconds after ending?

Share this post


Link to post

I need a script to stopp all containers at a given time, and then restart them again after xx minutes. I want to run duplicati on my appdata once a week and for the backup to be done properly I need the dockers to be stopped during backup.

 

Anyone have a script that I can use for this?

Share this post


Link to post
Posted (edited)
21 hours ago, ProphetSe7en said:

I need a script to stopp all containers at a given time, and then restart them again after xx minutes. I want to run duplicati on my appdata once a week and for the backup to be done properly I need the dockers to be stopped during backup.

 

Anyone have a script that I can use for this?

This script will stop the running dockers, sleep for a specified duration, and start the previously running dockers.

If you want to run your backup from this script, just replace "echo Pausing $pause..." and "sleep $pause" with your own code.

#!/bin/bash

pause=1m

running=$(docker ps --format "{{.Names}}" | sort -fV)

echo Stopping Dockers...
for docker in $running
{
	docker stop --time=30 $docker
}

echo Pausing $pause...
sleep $pause

echo Starting Dockers...
for docker in $running
{
	docker start $docker
}

pauseDockers.sh

 

Edit: Copy/Paste is a pain.

Edited by JoeUnraidUser

Share this post


Link to post
On 6/17/2019 at 8:58 AM, ProphetSe7en said:

I need a script to stopp all containers at a given time, and then restart them again after xx minutes. I want to run duplicati on my appdata once a week and for the backup to be done properly I need the dockers to be stopped during backup.

 

Anyone have a script that I can use for this?

A slightly different alternative would be to use the CA Backup & Restore plugin to backup your app & flash data.  That handles stopping and starting of containers automatically.  Then, to backup to the cloud, you could point duplicati at your appdata backup - then you've got on- and off-site backups.

 

Just a thought.

Share this post


Link to post

@JoeUnraidUser
Will take a look at the script. Thank you

8 hours ago, Cessquill said:

A slightly different alternative would be to use the CA Backup & Restore plugin to backup your app & flash data.  That handles stopping and starting of containers automatically.  Then, to backup to the cloud, you could point duplicati at your appdata backup - then you've got on- and off-site backups.

 

Just a thought.

This is how I have it setup now. I want to keep it this way, but in addition I want to create a backup of flashdrive/appdata using duplicati. In duplicati it is really easy to choose one file or folder to restore. That wont work if I take backup of the zip files from CA backup/restore.

If I figure out how to restore a singel file or folder the backup created by ca backup/restore I would probably drop duplicati for appdata folder.

Share this post


Link to post

I have an autoboot script that automatically starts my VM and dockers in the right sequence (for better NUMA memory allocation and docker dependencies etc.).

 

The funny thing is if I set it as run at array start, it gives me error that it can't communicate with virsh and docker (i.e. the services haven't started yet).

However, if I set it to run at FIRST array start, it runs perfectly fine.

 

I even tried to make the script wait x amount of seconds and went as far as 5 minutes and it still had the same can't comm with virsh and docker error. Maybe the script blocks the docker and virsh services or something?

 

It doesn't affect me much (I typically don't restart an array without reboot) but just thought to report it.

 

 

 

Share this post


Link to post

Hey team, I have noticed my server acting a bit buggy after a week or so and was thinking to use this(user scripts) to initiate a weekly reboot. I think this is built into the plugin but i didn't see a way to set or determine the day and time for the reboot. 

 

Though i have some tech background, unraid and linux are very new to me. Any help is greatly appreciated!

Share this post


Link to post
41 minutes ago, Aerodb said:

ee a way to set or determine the day and time for the reboot

Custom schedule, enter in a cron expression

 

http://corntab.com/

Share this post


Link to post
12 hours ago, Aerodb said:

Hey team, I have noticed my server acting a bit buggy after a week or so and was thinking to use this(user scripts) to initiate a weekly reboot. I think this is built into the plugin but i didn't see a way to set or determine the day and time for the reboot. 

You really should try to get to the bottom of your problem. It is not normal to need to reboot frequently. Many people only reboot when installing a new version of Unraid.

Share this post


Link to post
Posted (edited)

Hi, may some help what could be wrong with an python app running in user scripts

 

i get the following error in log when running from user scripts

 

script is simple as

 

#!/bin/bash

owi2plex -h 192.168.1.103 -u user -p pass- -b UHD -o /mnt/user/appdata/guide2go/enigmaUHD.xml >> /dev/null
 

when i run this from unraid terminal all is good, from user scripts its missing something ...

 

Traceback (most recent call last):
File "/usr/bin/owi2plex", line 11, in 
sys.exit(main())
File "/usr/lib64/python3.6/site-packages/click/core.py", line 764, in __call__
return self.main(*args, **kwargs)
File "/usr/lib64/python3.6/site-packages/click/core.py", line 696, in main
_verify_python3_env()
File "/usr/lib64/python3.6/site-packages/click/_unicodefun.py", line 124, in _verify_python3_env
' mitigation steps.' + extra
RuntimeError: Click will abort further execution because Python 3 was configured to use ASCII as encoding for the environment. Consult https://click.palletsprojects.com/en/7.x/python3/ for mitigation steps.

For any Tipps, thanks ahead

 

### EDIT ###

 

in case someone else could need it, had to add the following in the script

 

export LC_ALL=en_US.utf8

 

now it works ;)

Edited by alturismo
Fix found

Share this post


Link to post

hi i like to know using the cron guru generator site

to do every 3rd month  does this start whenever i save the crontab

“At 04:00 on day-of-month 1 and on Monday in every 3rd month.”

0 4 1 */3 1

or does it change everytime you reboot unraid

 

now my other one i tried is 

doing this to start From January and do ever 3 months 

“At 04:00 on day-of-month 1 and on Monday in every 3rd month from January through December.”

0 4 1 1/3 1

 

now the 2nd option is what i perfer... least for now..  but the cronguru page says it may not work on some cron jobs.. will that work for unraid the 2nd option..

"non standard! May not work with every cron."  is the error on the page i get..

 

and if i wanted to do specific months how does it work for unraid..  i tried some other crontab jobs examples like JAN APR AUG NOV   for the month section  but unraid didnt like that....

 

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.