Wanted: Simple chmod script?

Come up with a useful post-processing script? Share it here!
Post Reply
absteeve
Newbie
Newbie
Posts: 21
Joined: January 3rd, 2014, 12:57 pm

Wanted: Simple chmod script?

Post 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?
User avatar
safihre
Administrator
Administrator
Posts: 5338
Joined: April 30th, 2015, 7:35 am
Contact:

Re: Wanted: Simple chmod script?

Post 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!
If you like our support, check our special newsserver deal or donate at: https://sabnzbd.org/donate
absteeve
Newbie
Newbie
Posts: 21
Joined: January 3rd, 2014, 12:57 pm

Re: Wanted: Simple chmod script?

Post 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.
User avatar
safihre
Administrator
Administrator
Posts: 5338
Joined: April 30th, 2015, 7:35 am
Contact:

Re: Wanted: Simple chmod script?

Post 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
If you like our support, check our special newsserver deal or donate at: https://sabnzbd.org/donate
absteeve
Newbie
Newbie
Posts: 21
Joined: January 3rd, 2014, 12:57 pm

Re: Wanted: Simple chmod script?

Post 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.
absteeve
Newbie
Newbie
Posts: 21
Joined: January 3rd, 2014, 12:57 pm

Re: Wanted: Simple chmod script?

Post 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.
User avatar
safihre
Administrator
Administrator
Posts: 5338
Joined: April 30th, 2015, 7:35 am
Contact:

Re: Wanted: Simple chmod script?

Post 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.
If you like our support, check our special newsserver deal or donate at: https://sabnzbd.org/donate
absteeve
Newbie
Newbie
Posts: 21
Joined: January 3rd, 2014, 12:57 pm

Re: Wanted: Simple chmod script?

Post 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.
absteeve
Newbie
Newbie
Posts: 21
Joined: January 3rd, 2014, 12:57 pm

Re: Wanted: Simple chmod script?

Post 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.
User avatar
safihre
Administrator
Administrator
Posts: 5338
Joined: April 30th, 2015, 7:35 am
Contact:

Re: Wanted: Simple chmod script?

Post by safihre »

:)
If you like our support, check our special newsserver deal or donate at: https://sabnzbd.org/donate
Post Reply