[Plugin] CA User Scripts


Recommended Posts

On 9/20/2019 at 10:51 AM, DZMM said:

Hi can I get some help with what is probably an easy fix please.  

 

I've started using this python utility https://github.com/adamgot/python-plexlibrary where I've saved the files to /mnt/user/appdata/other/python-plexlibrary-master.  When I run the python utility via command line from the folder e.g.

 


python plexlibrary movies_recommended

everything works fine, but when I try to do via script e.g:

 


#!/bin/bash

cd /mnt/user/appdata/other/python-plexlibrary-master 

python plexlibrary movies_recommended

exit

I get this error:

 


Traceback (most recent call last):
File "/usr/lib64/python2.7/runpy.py", line 174, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "/usr/lib64/python2.7/runpy.py", line 72, in _run_code
exec code in run_globals
File "/mnt/user/appdata/other/python-plexlibrary-master/plexlibrary/__main__.py", line 3, in
main()
File "plexlibrary/plexlibrary.py", line 61, in main
r.run(args.sort_only)
File "plexlibrary/recipe.py", line 696, in run
missing_items, list_count = self._run()
File "plexlibrary/recipe.py", line 172, in _run
matching_total, item['title'], item['year']))
UnicodeEncodeError: 'ascii' codec can't encode character u'\u2013' in position 23: ordinal not in range(128)

I've also tried:

 


#!/usr/bin/env python

cd /mnt/user/appdata/other/python-plexlibrary-master

plexlibrary movies_recommended
plexlibrary movies_imdb_top_250

exit

Help please

Help please

Me again.  Can someone tell me what I'm doing wrong to run a python script please.  When I run the commands:

 

cd /mnt/user/appdata/other/python-plexlibrary-master

python plexlibrary movies_recommended

via putty all is well, but when I try to run a script:

 

#!/bin/bash

cd /mnt/user/appdata/other/python-plexlibrary-master

python plexlibrary movies_recommended

exit

I get errors.

Link to comment
  • 2 weeks later...

Unraid Newb here. I recently setup a fully automated experience with Plex, Sonarr, Radarr, qbittorrent, and Jackett. I have qbittorrent set to automatically remove torrents after either a 1:1 ratio or after 7 days (to fulfill all tracker seeding requirements). However, I noticed its removing the torrent from qbitt but not removing it from /mnt/user/downloads. So I downloaded CA User Scripts and wrote a one liner to handle this:

sudo find /mnt/user/downloads/ -mtime +7 -exec rm -rf {} \;

Is there a better way to do this? Its preferable to remove the file in /mnt/user/downloads by the downloader. Does anyone know if rtorrent does this?

Link to comment

I'am using a script for snapshotting VMs on BTRFS formatted drive which informs me via telegram when finished. Switching to 6.8.RC4 and adjusting some paths in the script I've noticed some german letters (ä ö ü) getting removed by the script when saving. Never happened in earlier builds. The affected line is the following:

/usr/local/emhttp/webGui/scripts/notify -i normal -s "BTRFS Send/Receive beendet" -d "Script ausgefhrt" -m "$(date '+%Y-%m-%d %H:%M') Information: BTRFS VM Offline Snapshot auf HDD erfolgreich abgeschlossen"

It should be "Script ausgeführt" not "ausgefhrt". Is this an issue from the plugin itself or caused by unraid. I think there was an update for user scripts since I am on 6.8RC but not 100% sure. Any idea how to fix this?

 

full script:

#!/bin/bash
#backgroundOnly=false
#arrayStarted=true
cd /mnt/cache/VMs_backup
sd=$(echo VMs_backup_off* | awk '{print $1}')
ps=$(echo VMs_backup_off* | awk '{print $2}')

if [ "$ps" == "VMs_backup_offline_$(date '+%Y%m%d')" ]
then
    echo "There's already a snapshot from today"
else
	for i in `virsh list | grep running | awk '{print $2}'`; do virsh shutdown $i; done
	
		# Wait until all domains are shut down or timeout has reached.
		END_TIME=$(date -d "300 seconds" +%s)

		while [ $(date +%s) -lt $END_TIME ]; do
			# Break while loop when no domains are left.
			test -z "`virsh list | grep running | awk '{print $2}'`" && break
			# Wait a little, we don't want to DoS libvirt.
			sleep 1
		done
	echo "shutdown completed"
	virsh list | grep running | awk '{print $2}'
    btrfs sub snap -r /mnt/cache/VMs /mnt/cache/VMs_backup_offline_$(date '+%Y%m%d')
	for i in `virsh list --all --autostart|awk '{print $2}'|grep -v Name`; do virsh start $i; done
	sync
    btrfs send -p /mnt/cache/VMs_backup/$ps /mnt/cache/VMs_backup_offline_$(date '+%Y%m%d') | btrfs receive /mnt/disks/VMs_backup_hdd
        if [[ $? -eq 0 ]]; then
        /usr/local/emhttp/webGui/scripts/notify -i normal -s "BTRFS Send/Receive beendet" -d "Script ausgefhrt" -m "$(date '+%Y-%m-%d %H:%M') Information: BTRFS VM Offline Snapshot auf HDD erfolgreich abgeschlossen"
        btrfs sub del /mnt/cache/$sd
        #btrfs sub del /mnt/disks/VMs_backup_HDD/VMs_backup/$sd
        else
        /usr/local/emhttp/webGui/scripts/notify -i warning -s "BTRFS Send/Receive gescheitert" -d "Script abgebrochen" -m "$(date '+%Y-%m-%d %H:%M') Information: Es wurde heute bereits ein Offline Snapshot erstellt"
        fi
fi

 

Link to comment
27 minutes ago, bastl said:

@Squid If I change it inside the Unraid ui, you say this is how it is? I never changed the script file itself only via ui and it always worked. 😂 No external editor involved.

There was a change introduced to strip out non-ascii characters to allow for those who did a copy/paste from forum posts as that was inserting hidden characters.

Link to comment
Just now, itimpi said:

I believe it is the editor built into the plugin.    Thus the suggestion to use an alternative editor.

All in all it's not a big deal. If I edit the script file itself with an external editor the notification comes through correctly. As long as not all german words are filtered out, I'am fine with it 😂

 

Link to comment
6 minutes ago, scubieman said:

Can i run user scripts remotely? even from different computer or phone inside network?

 

I want to move items from one folder to another. but i want to control when it happens.

You can always run a User Script manually from the Unraid GUI.    Therefore if you can get to the GUI you can run the script whenever you want.

  • Like 1
Link to comment
  • 2 weeks later...

Using the plugin I can't save any schedule options.  When I select something such as Scheduled Daily I click apply but nothing happens.  When I click done and look again the schedule is disabled.  It  won't save for some reason.  Does anyone know how to fix this?  I'll attach diagnostics here.

 

 

Edited by Viperean
removed diagnostics.zip
Link to comment
13 hours ago, Viperean said:

Using the plugin I can't save any schedule options.  When I select something such as Scheduled Daily I click apply but nothing happens.  When I click done and look again the schedule is disabled.  It  won't save for some reason.  Does anyone know how to fix this?  I'll attach diagnostics here.

 

tower-diagnostics-20191112-0241.zip 126.55 kB · 2 downloads

post the contents of /config/plugins/user.scripts/schedule.json on the flash drive

Link to comment

In the 6.8 RC5 release notes, it says this:

 



In another step toward better security, the USB flash boot device is configured so that programs and scripts residing there cannot be directly executed (this is because the 'x' bit is set now only for directories).  Commands placed in the 'go' file still execute because during startup, that file is copied to /tmp first and then executed from there.  If you have created custom scripts you may need to take a similar approach.

 

I have some custom scripts running with user scripts plugin on boot up. Do we have to change anything?

Link to comment
35 minutes ago, Squid said:

The plugin has never executed scripts directly from the flash drive

Ahh, but I call other CA User Scripts from their location on the flash drive.

 

Here is one of my scripts that runs at array start.

#!/bin/bash
echo "/boot/config/plugins/user.scripts/scripts/StartVM/script" | at now

I do it like that because if I call the StartVM script directly at array start, it hangs the array starting process, calling it this way works fine.

 

What path should I use instead of /boot/config/... ?

Link to comment
10 minutes ago, jonathanm said:

What path should I use instead of /boot/config/... ?

You have to either copy them say to /tmp and reference that (and change the permissions appropriately) or change the line to

echo "/bin/bash /boot/config/plugins/user.scripts/scripts/StartVM/script" | at now

 

Calling a script on the flash drive directly will run afoul of the security, because even though the plugin has never executed scripts directly from the flash, it has no control over what the script actually does.

Edited by Squid
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.