[Plugin] CA User Scripts


Recommended Posts

1 hour ago, hmgnsd said:

Hello all! Would anyone be able to cast their eyes over a couple of scripts I have ‘adapted’ for my download setup?

 

The first one I don’t think there is a problem with, it should move Handbrake converted files from one directory to another where a media manager can pick them up:

 

 

The next one, is supposed to delete the original files after they have been copied.

 

 The last time I tried it, it looked like it was removing files from all directories which was not the desired effect.

 

 

why not set the output folder for handbrake as your blackhole folder?

Link to comment

Thank you for the suggestion, I have looked at other possibilities before finding something that works for me regarding radarr/sonarr and post processing media. I can go in an delete the left overs manually but if I can get this script working it’d be much less maintenance.

Link to comment

OK, anyone? This script to move files from one directory to another is removing the source directory if empty after it runs , how can I prevent it doing that?

 

#!/bin/bash

if [ -f /var/run/mymover.pid ]; then
 if ps h `cat /var/run/mymover.pid` | grep mymover.sh ; then
   echo "mymover already running, sorry."
   exit 0
 fi
fi

echo $$ >/var/run/mymover.pid

echo "Moving files from $1 to $2"
(cd "/mnt/user/downloads/Complete/"; find -depth -print \( ! -exec fuser -s '{}' \; -exec rsync -i -qdIWRpEAXogt --numeric-ids --inplace --remove-source-files {} "/mnt/user/downloads/Import/" \; \))

# Prune empty directories from source dir
find "/mnt/user/downloads/Complete/" -type d -empty -prune -exec rmdir --ignore-fail-on-non-empty {} \;

# Prune empty directories from destination dir
find "/mnt/user/downloads/Import/" -type d -empty -prune -exec rmdir --ignore-fail-on-non-empty {} \;

sync

rm /var/run/mymover.pid

echo "Moving all done."

 

Link to comment
2 minutes ago, BRiT said:

Remove or comment out the line under the comment of # Prune empty directories from source dir

 

Ah, that's moving stuff but now /mnt/user/downloads/complete/season 01/ directory is left, for example... There's no way of getting the subdirectories from /complete/ moved without it deleting the directory /complete/ is it's empty?

 

Am I making sense? I feel like I'm not. 

Link to comment

COuld someone help me?

 

I would like a script which limit nzbget if IP1 and or IP2 are online.

 

Ive found https://nzbget.net/api/ but no exemple, and since i cant code... 

 

Something like

if {

ping 192.168.0.1 | 192.168.0.2

search for *not reachable*

}

http... /limit/nzbget 0 (no limit)

else { 

 

http.../limit/nzbget 500 } (means 500kbs)

 

Edited by nuhll
Link to comment
5 hours ago, hmgnsd said:

Am I making sense? I feel like I'm not. 

Well, here's what you said.

5 hours ago, hmgnsd said:

This script to move files from one directory to another is removing the source directory if empty after it runs , how can I prevent it doing that?

and then you said...

5 hours ago, hmgnsd said:

now /mnt/user/downloads/complete/season 01/ directory is left

It sounds like in the first post you want the empty folders left behind, in the second post you complain that it left them behind.

 

So no, you aren't making sense.

Link to comment
1 minute ago, jonathanm said:

Well, here's what you said.

and then you said...

It sounds like in the first post you want the empty folders left behind, in the second post you complain that it left them behind.

 

So no, you aren't making sense.

 

My apologies! Let me simplify; I would like the script to move the files and folders in the directory /downloads/complete/. What I have noticed, is that when that directory is empty and the script runs, it actually removes the directory /downloads/complete/.

 

How could I adapt it to move the contents of the directory, but not remove the directory itself when empty?

Link to comment
5 minutes ago, hmgnsd said:

 

My apologies! Let me simplify; I would like the script to move the files and folders in the directory /downloads/complete/. What I have noticed, is that when that directory is empty and the script runs, it actually removes the directory /downloads/complete/.

 

How could I adapt it to move the contents of the directory, but not remove the directory itself when empty?

I think that if you changed the second phase to start with a ‘cd’ like in the first phase it will give you the results you want.

Link to comment
4 minutes ago, itimpi said:

I think that if you changed the second phase to start with a ‘cd’ like in the first phase it will give you the results you want.

Like this?

# Prune empty directories from source dir
find cd "/mnt/user/downloads/Complete/" -type d -empty -prune -exec rmdir --ignore-fail-on-non-empty {} \;

I get this error?

 

.
find: `cd': No such file or directory
Moving all done.

 

Link to comment

how about this.

 

# Prune empty directories from source dir
find "/mnt/user/downloads/Complete/*" -type d -empty -prune -exec rmdir --ignore-fail-on-non-empty {} \;

# Prune empty directories from destination dir
find "/mnt/user/downloads/Import/*" -type d -empty -prune -exec rmdir --ignore-fail-on-non-empty {} \;

 

 

Link to comment
2 minutes ago, kizer said:

how about this.

 


# Prune empty directories from source dir
find "/mnt/user/downloads/Complete/*" -type d -empty -prune -exec rmdir --ignore-fail-on-non-empty {} \;

# Prune empty directories from destination dir
find "/mnt/user/downloads/Import/*" -type d -empty -prune -exec rmdir --ignore-fail-on-non-empty {} \;

 

 

hmm, still moves but throws up

 

.
find: `/mnt/user/downloads/Complete/*': No such file or directory
/tmp/user.scripts/tmpScripts/Move Completed Downloads/script: line 17: -empty: command not found
find: `/mnt/user/downloads/Import/*': No such file or directory
/tmp/user.scripts/tmpScripts/Move Completed Downloads/script: line 21: -prune: command not found
Moving all done.

 

Link to comment

Ok I'm trying to figure out exactly what your trying to do. 

 

On my machine anything that is in this folder gets moved to this folder.

mv /mnt/cache/uploads/* /mnt/user/Movies/All/

 

You have a bunch of code for pruning and other things and I'm kinda lost of what exactly your attempting to do. 

Link to comment
1 minute ago, kizer said:

Ok I'm trying to figure out exactly what your trying to do. 

 

On my machine anything that is in this folder gets moved to this folder.

mv /mnt/cache/uploads/* /mnt/user/Movies/All/

 

You have a bunch of code for pruning and other things and I'm kinda lost of what exactly your attempting to do. 

 

Ah, not my code. Copied from another thread where someone adapted the unRAID mover script. What I'd like is for everything to be moved from /mnt/user/downloads/Complete to /mnt/user/downloads/Import without the /Complete/ directory being removed.

 

I'm really appreciating the replies :)

Link to comment
15 minutes ago, hmgnsd said:

hmm, still moves but throws up

 


.
find: `/mnt/user/downloads/Complete/*': No such file or directory
/tmp/user.scripts/tmpScripts/Move Completed Downloads/script: line 17: -empty: command not found
find: `/mnt/user/downloads/Import/*': No such file or directory
/tmp/user.scripts/tmpScripts/Move Completed Downloads/script: line 21: -prune: command not found
Moving all done.

 

Could you post the exact script that produced this output? I am wondering if you haven't tried but failed to type the script that kizer gave.

Link to comment
25 minutes ago, trurl said:

Could you post the exact script that produced this output? I am wondering if you haven't tried but failed to type the script that kizer gave.

 

sure

 

#!/bin/bash

if [ -f /var/run/mymover.pid ]; then
 if ps h `cat /var/run/mymover.pid` | grep mymover.sh ; then
   echo "mymover already running, sorry."
   exit 0
 fi
fi

echo $$ >/var/run/mymover.pid

echo "Moving files from $1 to $2"
(cd "/mnt/user/downloads/Complete/"; find -depth -print \( ! -exec fuser -s '{}' \; -exec rsync -i -qdIWRpEAXogt --numeric-ids --inplace --remove-source-files {} "/mnt/user/downloads/Import/" \; \))

# Prune empty directories from source dir
find "/mnt/user/downloads/Complete/*" -type d -empty -prune -exec rmdir --ignore-fail-on-non-empty {} \;

# Prune empty directories from destination dir
find "/mnt/user/downloads/Import/*" -type d -empty -prune -exec rmdir --ignore-fail-on-non-empty {} \;

sync

rm /var/run/mymover.pid

echo "Moving all done."

 

Link to comment

Can I make a feature request please.  Can the scripts be sorted by the name give under 'Edit Name' rather than the original script name please. 

 

I've changed the names of many of my scripts from what they were originally created as e.g. my script 'fuse rclone install and mount' was originally called 'rclone_install_and_mount' and hence is stored at boot/config/plugins/user.scripts/scripts/rclone_install_and_mount, which is controlling the sort. 

 

Ideally I'd want to be able to change the names of my scripts to add prefixes e.g. 'PLEXDRIVE: fuse rclone install and mount' & 'PLEXDRIVE: rclone_upload_plexdrive' - so that they are grouped together but it won't work unless I go and change the actual script filename.

Link to comment

I have a feature request as well.

 

I am looking at an easy way to have a script available both via the plugin and from the command line.   One way I though of achieving this would be to set up a symbolic link under /usr/local/bin that pointed to the script file on the flash.    I could do this myself in the current implementation by running the appropriate commands on each boot of the system, but it would be neater if the plugin did this on my behalf.   I cannot think of any obvious downsides (but I may have missed something).

 

Another option might be to allow the plugin to point to an external script file on the flash, but this seems more of an effort to implement and provide no obvious benefits over the approach outlined above.

Link to comment
2 hours ago, itimpi said:

One way I though of achieving this would be to set up a symbolic link under /usr/local/bin that pointed to the script file on the flash

 

This directory is used by other internal scripts as well. The only risk I see with your approach is a naming conflict, if something is accidentally called the same as one of the internal scripts.

Link to comment
3 hours ago, itimpi said:

Another option might be to allow the plugin to point to an external script file on the flash

This actually has been on the todo list for quite awhile, but it introduces a complication because by design to make life easier for the end-user, all scripts are not executed in place, but rather from /tmp after having their line endings normalized for linux.  Because of that, any scripts already existing that may have other dependencies within their own directory may or may not work properly.

 

Plus, you can simply make a script to cd and then execute the required script anyways.

Link to comment
39 minutes ago, BRiT said:

I wouldnt symlink things, I'd merely expand the Path setting inside the bashrc/profile to include the user scripts, but make sure its added last so they wont have naming conflicts.

I thought of that, but each script is in its own folder which makes that approach a bit unwieldy

  • Upvote 1
Link to comment

Anyone know how to fix this error in the script.. :(

delete_dangling_images broken

Script location: /tmp/user.scripts/tmpScripts/delete_dangling_images/script
Note that closing this window will abort the execution of this script
"docker rmi" requires at least 1 argument.
See 'docker rmi --help'.

Usage: docker rmi [OPTIONS] IMAGE [IMAGE...] [flags]

Remove one or more images
Finished
if an error shows above, no dangling images were found to delete

Link to comment
Anyone know how to fix this error in the script..
delete_dangling_images broken
Script location: /tmp/user.scripts/tmpScripts/delete_dangling_images/script
Note that closing this window will abort the execution of this script
"docker rmi" requires at least 1 argument.
See 'docker rmi --help'.

Usage: docker rmi [OPTIONS] IMAGE [iMAGE...] [flags]

Remove one or more images
Finished
if an error shows above, no dangling images were found to delete
What error? The script states that if an error appears no dangling images were found.
  • Upvote 1
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.