Re: Bash assistance

From: Chris F.A. Johnson (cfajohnson_at_gmail.com)
Date: 01/18/05


Date: 17 Jan 2005 23:11:18 GMT

On Mon, 17 Jan 2005 at 16:13 GMT, Eric M. Jackson wrote:
> I'm in the processes of building bash scripts to automate common tasks.
>
> One thing I am trying to do it create a script called securehome.sh for
> users to run that will set their home directories to be more secure. In
> doing this I set access on all files and dirs in the user's home so that
> only the user themselves has access, however, I need to then go back and
> reset the permissions on the public_html dir and all the sub directories
> and files so that the user's web page continues to remain accessible to
> others.
>
> The part of the script the locks down the users home is simple enough
>
> cd
> chmod g-rwx,o-rwx * -R
> chmod 711 public_html
>
> So I broke the public_html tasks into various parts.
>
> 1). Goto user ~homedir/public_html
> 2). Pull in "ls" of ~homedir/public_html (Storing in array, for test
> just set array up manually for now)

   Why? Just:

chmod -R a+r,go-w $HOME/public_html/*

   If you really want to, you can create an array of directories by:

dirs=( $HOME/public_html/*/ )

> 3). Parse array to get elements (Use while loop)
> 5). Set dir permissions, Set file permisions, store sub dirs array,
> (if statements on elements using -d test to set either chmod 711 for
> dirs or chmod 744 for files, store dirs in new array)
> 5). Recursive call to go through and set do Step 3 for all subdirs (use
> new array created).
> 6). Create log of last run in user home.
>
> So I got everything working except the essential step 2. Any advice
> would be helpful, basically I just want to know the best way to take the
> output from ls and break it down in a way that will allow me to store it
> in an array.

    Why do all that?

## set $HOME/public_html to drwx--x--x
chmod 711 $HOME/public_html

## Add read permissions to all files under $HOME/public_html
chmod -R a+r $HOME/public_html

## Set execute permissions on all directories under $HOME/public_html
find $HOME/public_html -type d -exec chmod a+x,go-rw {} \;

-- 
    Chris F.A. Johnson                        http://cfaj.freeshell.org
    ===================================================================
    My code (if any) in this post is copyright 2004, Chris F.A. Johnson
    and may be copied under the terms of the GNU General Public License


Relevant Pages

  • Re: best way to distribute an item to everyones homedir?
    ... chmod and chown to change the permissions as you want them to be changed. ... How I do something like this is to build the script one line at a time using ...
    (freebsd-questions)
  • Bash assistance
    ... The part of the script the locks down the users home is simple enough ... chmod g-rwx,o-rwx * -R ... Parse array to get elements ... Set dir permissions, Set file permisions, store sub dirs array, ...
    (alt.os.linux)
  • Re: cygwin public domain korn shell scripts on windows xp: Permission denied
    ... When I attempt to run a script I get a "cannot execute - Permission ... the permissions on the script file. ... $ chmod 744 dummy.ksh ... I don't get any error message but the permissions are not affected. ...
    (comp.unix.questions)
  • Re: Bash assistance
    ... Will find directories and files and chmod them 711 or 744, ... > The part of the script the locks down the users home is simple enough ... store dirs in new array) ...
    (alt.os.linux)
  • Re: CHMOD help
    ... >I'm creating a script that will work in many servers, and there's this part, ... >the central server, opens the file, and in adda line by line in the client ... You pass an *ABSOLUTE FILE PATHNAME* to chmod. ... file has the permissions on, ...
    (comp.lang.php)