[Plugin] CA User Scripts


Recommended Posts

  • 2 weeks later...

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

 

Link to comment

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

 

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

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

Link to comment

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.  

Link to comment

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.

 

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

Link to comment

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)

Link to comment

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

Link to comment

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

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

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?

Link to comment
  • 2 weeks later...

Hi All,

 

I'm using the user scripts plugin to run a custom script every 5 minutes. I've set it up via the GUI, and I provided "*/5 * * * " in the custom field and applied the changes. However, I don't think my script is running every 5 minutes (I'm looking for a log file the script writes to and the log file doesn't get updated with the right timestamps). Am I missing any final steps to run the script periodically? /etc/cron.d/root file does seem to have an entry for my script....

 

Thanks!

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.