Page 1 of 1

[Linux] Owner Changer

Posted: May 15th, 2012, 4:09 pm
by Mohinder
Hi there!

For those who run SABnzbd as root, for some reason, but want to change the owner and permissions of files downloaded, here is a very simple script I wrote.

It changes the owner and group of all downloaded folders and files, permissions of all folders and sub-folders and permissions of all files, even those with spaces.

It works with BusyBox too, which is shipped with every NAS, i.e. without the -exec or -print0 and -0 arguments of the find and xargs commands.

Code: Select all

#!/bin/sh
# Owner Changer for SABnzbd 0.2
# By Mohinder <mohinder@no-log.org>

# Define the username, group and permissions to apply here
USER="romain"
GROUP="everyone"
FOLDERS="755"
FILES="644"

# Human readable variables
DESTINATION=$1

# Running the script
chown -R $USER:$GROUP "$DESTINATION"
find "$DESTINATION" -type d | while read i; do chmod $FOLDERS "$i"; done
find "$DESTINATION" -type f | while read i; do chmod $FILES "$i"; done

echo "Owner and permissions changed successfully."
Enjoy! :-)

Re: [Linux] Owner Changer

Posted: November 20th, 2012, 4:36 pm
by robcauss
question for you, do I need to change the $1 beside destination to the actual destination directory I want affected by the perm changes?

Re: [Linux] Owner Changer

Posted: November 21st, 2012, 12:43 pm
by dustoff
$1 is the first field after the name of the script, so its usage would be something like

script target

Then it changes the permissions and ownership of whatever "target" is.
If it is a directory all of the files and subdirectories in it.