sab docker in unraid - bash script not running

Come up with a useful post-processing script? Share it here!
live4soccer7
Newbie
Newbie
Posts: 17
Joined: June 6th, 2016, 1:09 am

sab docker in unraid - bash script not running

Post by live4soccer7 »

So I've made a script that pretty much cleans up unwanted files within specific categories. I know there is a cleanup list in sab settings, but it is a global setting from what I can see.

Anways, I've been able to run the script manually in the specific folder that I want (not automated/postprocess) and it works like a charm, but as soon as I change the path that I'm using to $1 and then do a chmod 777 or chmod +x and put the script in the sab script folder and select the script in sab and apply it to a category it will not work. I've confirmed the permission on the file.

Sab even tell me this: Ran sab_cleanup_script_post_process.sh
I saw that I could see the script output, so I clicked on it and it is completely blank.

Seeing that result, I put a simple echo of $1 and commented out everything else. Still nothing shows up in the script output. Once I did that Sab said, "View Script Output" below the filename once it was done downloading instead of "Ran sab_cleanup_script_post_process.sh"

It is all in BASH. Any ideas on what could be going on. Can it not be in bash? Does it have something with being in a docker?


Thank you very much for any input/advice. It is greatly appreciated.
User avatar
shypike
Administrator
Administrator
Posts: 19774
Joined: January 18th, 2008, 12:49 pm

Re: sab docker in unraid - bash script not running

Post by shypike »

live4soccer7 wrote:but as soon as I change the path that I'm using to $1 and then do a chmod 777 or chmod +x and put the script in the sab script folder and select the script in sab and apply it to a category it will not work. I've confirmed the permission on the file.
Not sure what you mean by "as soon as I change the path that I'm using to $1".
Make sure that you do this (the quotes matter).
cd "$1"

Also, the first line of a Bash script needs to be:
#!/bin/bash
live4soccer7
Newbie
Newbie
Posts: 17
Joined: June 6th, 2016, 1:09 am

Re: sab docker in unraid - bash script not running

Post by live4soccer7 »

I had a path where I was telling the script to process. Example: Desktop/folder/
Then I changed the path to $1 so that it would process the new downloads at their final destination as Sab describes in their post script processing page. I'll add quotes to it and see if that does the trick. Thanks and I'll post back.
live4soccer7
Newbie
Newbie
Posts: 17
Joined: June 6th, 2016, 1:09 am

Re: sab docker in unraid - bash script not running

Post by live4soccer7 »

This is the exact argument I'm using at this time

find "$1" -name *$junk -type f -exec rm -f -v {} \;
User avatar
shypike
Administrator
Administrator
Posts: 19774
Joined: January 18th, 2008, 12:49 pm

Re: sab docker in unraid - bash script not running

Post by shypike »

I think this should be:

Code: Select all

find "$1" -name '*'$junk -type f -exec rm -f -v {} \;
Without single quotes around *, it will be expanded before you even reach $1
What is in $junk? Just a single extension?
live4soccer7
Newbie
Newbie
Posts: 17
Joined: June 6th, 2016, 1:09 am

Re: sab docker in unraid - bash script not running

Post by live4soccer7 »

I apologize, I should have provided the full script. It is from the "BASH Post Processing Script" Sticky in the forum.

Code: Select all

#!/bin/bash


topic1 () {


GARBAGE=".nfo .sfv .nzb .srr .info .idx .txt .com .db .md5 .par2 .png .1 .jpg .jpeg .url .lnk .html .ini .bat .com .exe .scr .sample .tbn .xml" #### Add or remove extensions here

for junk in $GARBAGE
do
find "$1" -name *$junk -type f -exec rm -f -v {} \;
done
echo "$1"
}

topic1
It ran just fine in when I had the script in the folder to look in and simply put "find ." instead of "find $1". I thought that the sab script information on their variable said they already had the spaces taken care of so I definitely didn't expect to have to have the quotes. I'm testing the above now. I should know in about an hour. Once it works, I'll remove the echo. I had it there for testing purposes.
live4soccer7
Newbie
Newbie
Posts: 17
Joined: June 6th, 2016, 1:09 am

Re: sab docker in unraid - bash script not running

Post by live4soccer7 »

Here is the newest feedback from SAB. This is the first time I've seen anything in the script output/log


find: cannot search `': No such file or directory
find: cannot search `': No such file or directory
find: cannot search `': No such file or directory
find: cannot search `': No such file or directory
find: cannot search `': No such file or directory
find: cannot search `': No such file or directory
find: cannot search `': No such file or directory
find: cannot search `': No such file or directory
find: cannot search `': No such file or directory
find: cannot search `': No such file or directory
find: cannot search `': No such file or directory
find: cannot search `': No such file or directory
find: cannot search `': No such file or directory
find: cannot search `': No such file or directory
find: cannot search `': No such file or directory
find: cannot search `': No such file or directory
find: cannot search `': No such file or directory
find: cannot search `': No such file or directory
find: cannot search `': No such file or directory
find: cannot search `': No such file or directory
find: cannot search `': No such file or directory
find: cannot search `': No such file or directory
find: cannot search `': No such file or directory
find: cannot search `': No such file or directory
find: cannot search `': No such file or directory
find: cannot search `': No such file or directory


It definitely didn't remove any files from the destination folder as there were all sorts of extra files that should have been removed.

I have added the single quotes around the * as in '*' and we will see if that does the trick. I'm not quite sure why it would have worked flawlessly when manually running it the original way I had it, but it seems there must be some difference.
live4soccer7
Newbie
Newbie
Posts: 17
Joined: June 6th, 2016, 1:09 am

Re: sab docker in unraid - bash script not running

Post by live4soccer7 »

Still the same results with the suggested changes. Hmm.... Any ideas?
live4soccer7
Newbie
Newbie
Posts: 17
Joined: June 6th, 2016, 1:09 am

Re: sab docker in unraid - bash script not running

Post by live4soccer7 »

I think it must be how SAB runs the script. If the script is run globally on the unraid machine and not actually within the SAB docker then that would explain why the path doesn't work. Even then, I can't get it to print $1 in the output log to see how it is formatted.

If it is ran globally on the server then the path would be different than the allowed path that is defined in the docker. If this is the case then I'd have to strip the final folder name off the $1 path and then add the actual global/absolute path to the real destination instead of the Alias that is created when using a docker by allowing it access to specific places on the unraid machine.

Thoughts?
live4soccer7
Newbie
Newbie
Posts: 17
Joined: June 6th, 2016, 1:09 am

Re: sab docker in unraid - bash script not running

Post by live4soccer7 »

I added this in the bash script to see if it actually outputs something and what it is giving for $1

echo this is the output of sab variable.."$1"...end
echo this is a test for sab to see if it will print
live4soccer7
Newbie
Newbie
Posts: 17
Joined: June 6th, 2016, 1:09 am

Re: sab docker in unraid - bash script not running

Post by live4soccer7 »

This was the output:


find: cannot search `': No such file or directory
find: cannot search `': No such file or directory
find: cannot search `': No such file or directory
find: cannot search `': No such file or directory
find: cannot search `': No such file or directory
find: cannot search `': No such file or directory
find: cannot search `': No such file or directory
find: cannot search `': No such file or directory
find: cannot search `': No such file or directory
find: cannot search `': No such file or directory
find: cannot search `': No such file or directory
find: cannot search `': No such file or directory
find: cannot search `': No such file or directory
find: cannot search `': No such file or directory
find: cannot search `': No such file or directory
find: cannot search `': No such file or directory
find: cannot search `': No such file or directory
find: cannot search `': No such file or directory
find: cannot search `': No such file or directory
find: cannot search `': No such file or directory
find: cannot search `': No such file or directory
find: cannot search `': No such file or directory
find: cannot search `': No such file or directory
find: cannot search `': No such file or directory
find: cannot search `': No such file or directory
find: cannot search `': No such file or directory
this is the output of sab variable.....end
this is a test for sab to see if it will print

It is clear that the Sab variable $1 is not doing anything. Any ideas now that this is getting narrowed down?
User avatar
sander
Release Testers
Release Testers
Posts: 9072
Joined: January 22nd, 2008, 2:22 pm

Re: sab docker in unraid - bash script not running

Post by sander »

A few days ago I saw a flow chart on twitter about shell programming
if the shell script does not work, try adding more quotes. If it still does not work, try removing double quotes
So true ... ;-(

My advice: use python. Easier to create and read, and cross-platform. I made this for you:

Code: Select all

#!/usr/bin/python

import os
import sys

listnotwanted = ['.exe', '.com', '.dll']	# in lower case

startdir = sys.argv[1]

for root, dirs, files in os.walk(startdir):
	path = root.split('/')
	for file in files:
		fullpath =  '/'.join(path) + '/' + file
		for notwant in listnotwanted:
			if fullpath.lower().endswith(notwant):
				print "go away:", fullpath
First run it from the CLI, then run it as a post-proc script.

Result on my system:

Code: Select all

go away: /home/sander/kul11/sabnzbd/win/nsis/Plugins/inetc.dll
go away: /home/sander/kul/eicar.com
go away: /home/sander/uploader3/uploadstuff/eicar.com
go away: /home/sander/kul-git-2014-05-16/sabnzbd/win/unrar/UnRAR.exe
go away: /home/sander/.winrar/drive_c/windows/regedit.exe
live4soccer7
Newbie
Newbie
Posts: 17
Joined: June 6th, 2016, 1:09 am

Re: sab docker in unraid - bash script not running

Post by live4soccer7 »

Thanks! I'll give it a shot and see what happens. I'm not familiar with python at all, so I'll definitely be looking a few things up to fully understand the syntax and functions.
User avatar
sander
Release Testers
Release Testers
Posts: 9072
Joined: January 22nd, 2008, 2:22 pm

Re: sab docker in unraid - bash script not running

Post by sander »

The only lines you need to change, and thus understand, are:

Code: Select all

listnotwanted = ['.exe', '.com', '.dll']   # in lower case
which is easy

and

Code: Select all

            print "go away:", fullpath
which you can replace with (or add this):

Code: Select all

            os.remove(fullpath)
One important note: correct indention is required in Python
live4soccer7
Newbie
Newbie
Posts: 17
Joined: June 6th, 2016, 1:09 am

Re: sab docker in unraid - bash script not running

Post by live4soccer7 »

Just to play around with a python script I did the following and have put it in post process to see if it gives me a path.

Code: Select all

#!/usr/bin/python

import os
import sys

directory = sys.argv[1]

print "go away:", directory
The problem that I was running in to was sab actually passing the correct information for $1 or 1. We will see if that prints out a path, if not then it won't matter what language the script is written in.
Post Reply