Page 1 of 1

Wanted: Simple chmod script?

Posted: January 3rd, 2018, 12:38 am
by absteeve
I know nothing of python or scripting and the wiki is all gibberish to me.

In Ubuntu, I have to manually run a few chmod commands after every download. Can someone give me a script that would do that automatically once a file is downloaded? Or is there a simple example somewhere that shows directly how to run shell commands on the files?

Re: Wanted: Simple chmod script?

Posted: January 3rd, 2018, 9:29 am
by safihre
You seem to know a lot about file-permissions, so the wiki shouldn't be gibberish to you ;)

With SABnzbd is a `scripts` folder that includes `Sample-PostProc.sh`, which shows you a simple script.
You can just adapt it to use the right parameter to give to your commands!

Re: Wanted: Simple chmod script?

Posted: January 3rd, 2018, 11:34 am
by absteeve
"shouldn't"?

It is.

So is the sample script. It isn't even a sample of anything. From what I can tell, all it does is echo back what I put in to call it? There is absolutely nothing there that is helpful in any way in determining how one would go about doing ANYTHING, let alone specifically what I want (which is only necessary because SAB doesn't quite handle permissions correctly). It could POSSIBLY be considered a slightly advanced "hello world", but even that is a stretch.

Between that "sample" and the sparse info in the WIKI regarding scripting.... I'm sorry, but I still have zero idea how to do it.

Re: Wanted: Simple chmod script?

Posted: January 3rd, 2018, 3:23 pm
by safihre
Have you tried using this script with a test job?
As also described in the wiki, the first parameter is the folder of the job:
https://sabnzbd.org/wiki/scripts/post-p ... ng-scripts

All you have to put in your script is:
chmod -R 777 $1

Re: Wanted: Simple chmod script?

Posted: January 3rd, 2018, 3:46 pm
by absteeve
That's it? I *literally* replace all the text in the sample script with that single line, save that file to the defined scripts folder and it'll work?


From a permissions perspective: That's poor form, although I'm sure you were just giving an example. Other than temporary testing, one should never use 777 permissions.

There would also be zero need for a script for that, since there's a configuration option in SAB that you can set to 777 if that's all you wanted.

Re: Wanted: Simple chmod script?

Posted: January 3rd, 2018, 4:11 pm
by absteeve
OK, so this is exactly what I did.

I put the following into a file called /opt/scripts/permissions.sh

Code: Select all

#!/bin/sh

find $1 -type d -exec chmod g+s {} \;
I set the permission of that script to 770

In Folders page, I browse to the/opt/ scripts folder, and in Categories I chose the script for each category. All seemed good.

BUT... I downloaded a file and in the end, the intended permission was NOT set.

Re: Wanted: Simple chmod script?

Posted: January 3rd, 2018, 4:50 pm
by safihre
And when you click on the History on the item, what does it show for the Script part? Should be at the bottom.
All output that your script writes to the screen is captured by Sab and shown in history, so this way you can debug.
It might be possible that after the Script step sabnzbd does another Permissions step.
I think you can prevent that by leaving the permissions in Config Folders empty.

Re: Wanted: Simple chmod script?

Posted: January 3rd, 2018, 5:20 pm
by absteeve
Thanks for the tip. OK... it exited with a 1 and says "No such file or directory". How can it internally provide the value for $1 and then not find it?

edit: Oh, I think I get it. I think the problem is due to spaces in the path. I need to figure out how to encapsulate $1 so that the results are quoted or properly escaped, I think.

Re: Wanted: Simple chmod script?

Posted: January 3rd, 2018, 5:42 pm
by absteeve
I just had to simply put quotes around the $1 and all is solved.

That was all very frustrating, but in the end - as you correctly pointed out - quite simple. I clearly have holes in my skillset.

Thank you very much safihre, for sticking with me on this.

Re: Wanted: Simple chmod script?

Posted: January 4th, 2018, 3:01 am
by safihre
:)