Jump to content
Squid

[Plugin] CA User Scripts

661 posts in this topic Last Reply

Recommended Posts

3 minutes ago, scubieman said:

dont see it 

Scroll down some more.

Share this post


Link to post

You need to install the dynamix Schedules plugin to be able to adjust the Daily/Weekly/Monthly times

  • Like 1

Share this post


Link to post
2 minutes ago, Squid said:

You need to install the dynamix Schedules plugin to be able to adjust the Daily/Weekly/Monthly times

That works better. Thank you!

Share this post


Link to post

Edit: Ignore - found a better way of tackling my problem

 

Can I get some help from someone more knowledgeable than me please.  What I want to do is check if a directory on my array is larger than 100GB e.g. check if /mnt/user0/downloads/nzbget is larger than 100GB.

 

The reason I want to do this is if I can work out how to do the check, if positive I'll pause my downloads as I'm finding that if mover moves too many files to the array before they are added to the right directory I start suffering IO meltdown.

 

Thanks in advance.

Edited by DZMM

Share this post


Link to post
7 minutes ago, DZMM said:

Can I get some help from someone more knowledgeable than me please.  What I want to do is check if a directory on my array is larger than 100GB e.g. check if /mnt/user0/downloads/nzbget is larger than 100GB.

 

The reason I want to do this is if I can work out how to do the check, if positive I'll pause my downloads as I'm finding that if mover moves too many files to the array before they are added to the right directory I start suffering IO meltdown.

 

Thanks in advance.

du -sh /mnt/user0/downloads/nzbget

 

Share this post


Link to post
40 minutes ago, trurl said:

du -sh /mnt/user0/downloads/nzbget

 

Thanks I know how to get the size, but how do I do the if bigger than 100GB then.... bit?

Share this post


Link to post

I'm trying to run the VM Config Backup script and receiving the errors in the code box below. The path that is to be used and was added to the config file is:

 

/mnt/user/030 - IT Support/Backup Data/Unraid/VM Settings

 

I pretty sure this is an issue with the spaces and/or the dash in the path name but I have tried a bunch of different syntax including single quotes, backslashes to remove the spaces, etc. Just cant seem to get it right. Can anybody assist with how this path should be defined in the config?

 

Thanks!

Script location: /tmp/user.scripts/tmpScripts/vm settings backup/script
Note that closing this window will abort the execution of this script
/tmp/user.scripts/tmpScripts/vm settings backup/script: line 10: [: too many arguments
As /mnt/user/030 - IT Support/Backup Data/Unraid/VM Settings//vmsettings/_27_Jan_2019 exists continuing.
Saving vm xml files
rsync: link_stat "/mnt/user/030" failed: No such file or directory (2)
rsync: link_stat "/-" failed: No such file or directory (2)
rsync: link_stat "/IT" failed: No such file or directory (2)
rsync: change_dir "/Support" failed: No such file or directory (2)
rsync: change_dir "/Data/Unraid" failed: No such file or directory (2)
rsync: mkdir "/Settings//vmsettings/_27_Jan_2019/xml" failed: No such file or directory (2)
rsync error: error in file IO (code 11) at main.c(664) [Receiver=3.1.3]
Saving ovmf nvram
rsync: link_stat "/mnt/user/030" failed: No such file or directory (2)
rsync: link_stat "/-" failed: No such file or directory (2)
rsync: link_stat "/IT" failed: No such file or directory (2)
rsync: change_dir "/Support" failed: No such file or directory (2)
rsync: change_dir "/Data/Unraid" failed: No such file or directory (2)
rsync: mkdir "/Settings//vmsettings/_27_Jan_2019/nvram" failed: No such file or directory (2)
rsync error: error in file IO (code 11) at main.c(664) [Receiver=3.1.3]
chmod: cannot access '/mnt/user/030': No such file or directory
chmod: cannot access '-': No such file or directory
chmod: cannot access 'IT': No such file or directory
chmod: cannot access 'Support/Backup': No such file or directory
chmod: cannot access 'Data/Unraid/VM': No such file or directory
chmod: cannot access 'Settings//vmsettings/_27_Jan_2019': No such file or directory

 

Share this post


Link to post
48 minutes ago, CraigGivant said:

I'm trying to run the VM Config Backup script and receiving the errors in the code box below. The path that is to be used and was added to the config file is:

 

/mnt/user/030 - IT Support/Backup Data/Unraid/VM Settings

 

I pretty sure this is an issue with the spaces and/or the dash in the path name but I have tried a bunch of different syntax including single quotes, backslashes to remove the spaces, etc. Just cant seem to get it right. Can anybody assist with how this path should be defined in the config?

Personally I wouldn't put spaces in a user share name just to avoid these sorts of problems.

Share this post


Link to post
18 minutes ago, trurl said:

Personally I wouldn't put spaces in a user share name just to avoid these sorts of problems.

I can appreciate that but the horse has already left the barn. I also believe this not only affects the share name but also the folders within the share. I migrated all data over from a Qnap and literally have thousands of folders. I certainly don't want to rename them all as even if there was a script to do this easily we have too many programs that would need to be re-pathed to find their data. I have had no issues with anything (including VM's and Dockers) using paths with spaces. I have only encounters it in this plugin as per above as well as with spaceinvaders icon pack downloader.

 

Hoping for a simple way to define this path properly to work with the scripts and if not I'll just have to create a different share.

Share this post


Link to post

I got this to work but not as eloquently as the original script. Once I figured out the path syntax, nothing I did would pass the backuplocation variable properly to the rest of the script. I removed the variable and directly entered the path in all instance of $dir. Here is what worked:

 

#!/bin/bash
#backs up
datestamp="_"`date '+%d_%b_%Y'`
mkdir -vp '/mnt/user/'030\ -\ IT\ Support'/'Backup\ Data'/Unraid/'VM\ Settings'/'$datestamp'/nvram'
mkdir -vp '/mnt/user/'030\ -\ IT\ Support'/'Backup\ Data'/Unraid/'VM\ Settings'/'$datestamp'/xml'
echo "Saving vm xml files"
rsync -a --no-o /etc/libvirt/qemu/*xml '/mnt/user/'030\ -\ IT\ Support'/'Backup\ Data'/Unraid/'VM\ Settings'/'$datestamp'/xml'
echo "Saving ovmf nvram"
rsync -a --no-o /etc/libvirt/qemu/nvram/* '/mnt/user/'030\ -\ IT\ Support'/'Backup\ Data'/Unraid/'VM\ Settings'/'$datestamp'/nvram'
chmod -R 777 '/mnt/user/'030\ -\ IT\ Support'/'Backup\ Data'/Unraid/'VM\ Settings'/'$datestamp'/xml'
chmod -R 777 '/mnt/user/'030\ -\ IT\ Support'/'Backup\ Data'/Unraid/'VM\ Settings'/'$datestamp'/nvram'
sleep 5
exit

Here is SpaceInvaderOne's original script for comparison:

 

#!/bin/bash
#backs up
#change the location below to your backup location 
backuplocation="/mnt/user/test/"

# do not alter below this line
datestamp="_"`date '+%d_%b_%Y'`
dir="$backuplocation"/vmsettings/"$datestamp"
# dont change anything below here
if [ ! -d $dir ] ; then
 
			echo "making folder for todays date $datestamp"

			# make the directory as it doesnt exist
			mkdir -vp $dir
		else
			echo "As $dir exists continuing."
			fi

echo "Saving vm xml files"
rsync -a --no-o /etc/libvirt/qemu/*xml $dir/xml/
echo "Saving ovmf nvram"
rsync -a --no-o /etc/libvirt/qemu/nvram/* $dir/nvram/
chmod -R 777 $dir
sleep 5
exit

 

Was quite a bit of experimenting for a rookie but worth the lessons learned. If anybody see anything out of whack I'd appreciate it but the files are saving to my chosen path in a dated folder.  

Share this post


Link to post

maybe it's buried somewhere in this thread but I didn't see it (I admit I didn't read every single post)... but when I choose a predefined option of "Run Weekly" exactly what day/time does it run? I'm going to guess it's weekly based on the time/day I hit the "apply" button? But wanted to make sure.

 

Share this post


Link to post
3 minutes ago, jpotrz said:

maybe it's buried somewhere in this thread but I didn't see it (I admit I didn't read every single post)... but when I choose a predefined option of "Run Weekly" exactly what day/time does it run? I'm going to guess it's weekly based on the time/day I hit the "apply" button? But wanted to make sure.

 

Actually, IIRC, it’s based on settings>scheduler>fixed schedules. It’ll run whenever you have unRAID set to run weekly schedules.

Share this post


Link to post
Actually, IIRC, it’s based on settings>scheduler>fixed schedules. It’ll run whenever you have unRAID set to run weekly schedules.
You also need to install the dynamic schedules plugin

Sent via telekinesis

Share this post


Link to post

I am having some trouble with getting "_" instead of spaces when running a script through user scripts.

 

the script is:

 

cd /mnt/user/YouTube/
python3 youtube-dl --config-location youtube-dl.conf

 

when I run a run.sh file with the unraid terminal containing just

python3 youtube-dl --config-location youtube-dl.conf

in the /mnt/user/YouTube/ directory, spaces are correctly created by youtube-dl in filenames.

 

anyone know how i could fix this?

Edited by potatows

Share this post


Link to post

Fully specify the config location.

Share this post


Link to post
19 minutes ago, BRiT said:

Fully specify the config location.

I tried just now and the same result occured.

 

I looked at the logs and noticed this:

 

"WARNING: Assuming --restrict-filenames since file system encoding cannot encode all characters. Set the LC_ALL environment variable to fix this."

 

i am not sure what i should be setting it to though

 

EDIT:

 

setting the LC_ALL variable for the command fixed it

for posterity i fixed this by changing the script to:

 

cd /mnt/user/YouTube/
env LC_ALL=en_US.UTF-8 python3 youtube-dl --config-location /mnt/user/YouTube/youtube-dl.conf

 

Edited by potatows

Share this post


Link to post

why not just python3 /mnt/user/YouTube/youtube-dl ..?

Share this post


Link to post
12 hours ago, nuhll said:

why not just python3 /mnt/user/YouTube/youtube-dl ..?

for some reason the language info doesn't get passed to youtube-dl unless you specify it with env LC_ALL=en_US.UTF-8. When that happens youtube-dl defaults to restrict filenames and replaces spaces with _. It does get passed when you run the command from a terminal though.

 

Edited by potatows

Share this post


Link to post

Probably in retrospect, this all makes perfect sense as user scripts doesn't execute any script through the shell, so any environment variables aren't set.  (This is also why you have to give items the full path in some cases vs when executing via a shell you don't have to)

Share this post


Link to post

Hello Team,

 

Hope you are all good. Am new to the unRaid world and have been liking every bit of it lately. @Squid I need your "help" with something.

 

I've added CA User Scripts together with Rclone docker from Wasesh. All is fine and working and I've had a backup running since yesterday to send data to my Onedrive (The backup is not huge but my internet is crap ...).

 

The sync is running in the background and wanted to stop it to let me have "normal' access to internet (since I'm caping my upload) but I don't see the button to stop the task. It's not a problem, I can kill the process via terminal, but I was wondering if you wanted to have a look if something is wrong or it's expected behaviour.

 

Let me know if you want and I'll send you whatever you need. Else, no biggie.

 

Cheers

Share this post


Link to post

Any long running processes spawned by the actual script do not always wind up getting killed.  The plugin does attempt to kill off any child processes of the script, but depending upon what that child does (ie: spawns another child) then it does not always work.  Creating another script that has your pkill command in it should however work correctly.

 

EDIT:  Looked at the code, and there *might* be a bug in user scripts attempting to kill the childs.  Will have to investigate further.  How I'm using pkill doesn't jive with the man page on it.  Can't remember exactly how I came up with the syntax I'm using.

Edited by Squid

Share this post


Link to post

Also user scripts doenst really see scripts running when they run a long time^^, but theres workarounds for that.

 

To kill rclone u can use that

ps -ef | grep "rclone" | grep -v 'grep' | grep -v 'mount' | awk '{ print $2 }' | xargs kill
 

 

it finds all rclones childs and kill all childs except the ones which work for mount (if u have that running).

Edited by nuhll

Share this post


Link to post

There may be a valid reason why this is not done already, but if you edit the name of the script, could it also update the name of the corresponding folder in the user.scripts\scripts directory?

 

When I'm working on something I'll often call it something like "z docker testing" to put it at the end of the list.  When finished, I rename it, but it still stays at the bottom.  I'm guessing the plugin sorts the scripts list by folder name?

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now