[Linux] Owner Changer

Come up with a useful post-processing script? Share it here!
Post Reply
Mohinder
Newbie
Newbie
Posts: 1
Joined: May 15th, 2012, 3:37 pm

[Linux] Owner Changer

Post 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! :-)
Last edited by Mohinder on May 17th, 2012, 11:13 am, edited 2 times in total.
robcauss
Newbie
Newbie
Posts: 1
Joined: October 21st, 2012, 10:52 pm

Re: [Linux] Owner Changer

Post 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?
dustoff
Newbie
Newbie
Posts: 1
Joined: January 17th, 2008, 3:20 pm

Re: [Linux] Owner Changer

Post 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.
Post Reply