Operating System - HP-UX
1753707 Members
5408 Online
108799 Solutions
New Discussion

split with FS a string (filesystem )

 
SOLVED
Go to solution
support_billa
Valued Contributor

split with FS a string (filesystem )

hello,

 

i have a filesystem and subdirectories like /mnt/db1/ORASID

 

i want to set dynamic for the mountpoint and db1 the user "root:sys" and only for dir ORASID the oracle user "oracle:dba":

 

/mnt           user root:sys

/mnt/db1    user root:sys

/mnt/db1/ORASID  user oracle:dba

 

here is my version , i am not happy

 

 

4 REPLIES 4
Dennis Handly
Acclaimed Contributor

Re: split with FS a string (filesystem)

>i want to set dynamic for the mountpoint and db1 the user "root:sys" and only for dir ORASID the oracle user "oracle:dba":

 

I'm not sure what you are trying to do?

 

You can optimize your script with:

  typeset -i i=0

 

>filesystem_split="${fs_split_ifs}""${filesystem[${i}]}"

>filesystem_split="${filesystem_split}""/""${filesystem[${i}]}"

 

Not sure why you have stuttered quotes.  You just need the outer ones:

    filesystem_split="${filesystem_split}/${filesystem[${i}]}"

 

(You also don't need ${} within subscripts, [i] will work fine.)

 

>i=$(( ${i} + 1 ))

 

You can replace this by: (( i += 1 ))

support_billa
Valued Contributor

Re: split with FS a string (filesystem)

hello,

 

better explanations : the last directory starting from root-directory "/" should get oracle user and permission , the other directories should get root :sys :

 

/mnt           user root:sys

/mnt/db1    user root:sys

/mnt/db1/ORASID  user oracle:dba

 

regards

 

Matti_Kurkela
Honored Contributor
Solution

Re: split with FS a string (filesystem)

Something like this, perhaps?

#!/bin/sh
DBOWNER=oracle:dba
ROOTOWNER=root:sys

# set DEBUG="" to actually do the job, or
# DEBUG="echo" to just output what would be done
DEBUG=echo

while [ "$1" != "" ]
do
    DBDIR="$1"
    $DEBUG chown $DBOWNER $DBDIR

    PARENT=$(dirname $DBDIR)
    while [ "$PARENT" != "/" ]
    do
        $DEBUG chown $ROOTOWNER $PARENT
        PARENT=$(dirname $PARENT)
    done
    shift
done

 

As is, the script will only display the commands it would run. First verify the script does what you want, then change the line 'DEBUG=echo' to 'DEBUG=""' to make it actually change the permissions instead of displaying the commands.

 

You can run the script with one or many command-line arguments. For example, if you save the script as ./oraperms.sh and mark it executable:

$ ./oraperms.sh /mnt/db1/ORASID
or
$ ./oraperms.sh /mnt/db1/ORASID /mnt2/db2/OTHERSID /third/deep/dir/db3/THIRDSID
or
$ ./oraperms.sh /mnt/db*/*SID

 

MK
Dennis Handly
Acclaimed Contributor

Re: split with FS a string (filesystem)

>here is my version, I am not happy

 

It seems to do its job.  What do you not like?

 

And you don't really need: fs_split_ifs="/"

Just always do:

filesystem_split="${filesystem_split}/${filesystem[i]}"