orainstRoot.sh 解釋

tw752發表於2015-03-16

[oracle@rh64 oraInventory]$ cat orainstRoot.sh

#!/bin/sh

#設定環境變數

AWK=/bin/awk

CHMOD=/bin/chmod

CHGRP=/bin/chgrp

CP=/bin/cp

ECHO=/bin/echo

MKDIR=/bin/mkdir

#檢驗當前使用者是不是root使用者

RUID=`/usr/bin/id|$AWK -F/( '{print $1}'|$AWK -F/) '{print $2}'`

if [ ${RUID} != "root" ];then

$ECHO "This script must be executed as root"

exit 1    #如果不是則退出,並輸出"This script must be executed as root"

fi

if [ -d "/etc" ]; then   #是否存在/etc目錄

$CHMOD 755 /etc;   #存在,確保/etc許可權改為755

else

$MKDIR -p /etc;        #若不存在,建立之

fi

if [ -f "/u01/app/oraInventory/oraInst.loc" ]; then         #是否存在oraInst.loc檔案

$CP /u01/app/oraInventory/oraInst.loc /etc/oraInst.loc;     #若存在,複製之到/etc

$CHMOD 644 /etc/oraInst.loc       #將其屬性改為644

else

INVPTR=/etc/oraInst.loc          #若不存在,一一建立並修改屬性

INVLOC=/u01/app/oraInventory

GRP=oinstall

PTRDIR="`dirname $INVPTR`";       #PTRDIR=/etc

# Create the software inventory location pointer file

if [ ! -d "$PTRDIR" ]; then

$MKDIR -p $PTRDIR;          #/etc不存在,穿件/etc

fi

$ECHO "Creating the Oracle inventory pointer file ($INVPTR)";

$ECHO inventory_loc=$INVLOC > $INVPTR           #inventory_loc=/u01/app/oraInventory寫入/etc/oraInst.loc

$ECHO inst_group=$GRP >> $INVPTR      #inst_group=oinstall寫入/etc/oraInst.loc

chmod 644 $INVPTR       #/etc/oraInst.loc許可權改為644

# Create the inventory directory if it doesn't exist

if [ ! -d "$INVLOC" ];then

$ECHO "Creating the Oracle inventory directory ($INVLOC)";

$MKDIR -p $INVLOC;            #inventory目錄不存在,就建立之

fi

fi

$ECHO "Changing permissions of /u01/app/oraInventory.

Adding read,write permissions for group.

Removing read,write,execute permissions for world.

";

$CHMOD -R g+rw,o-rwx /u01/app/oraInventory;       #給組新增讀寫/u01/app/oraInventory許可權,刪除對其他人的所有許可權

if [ $? != 0 ]; then

$ECHO "OUI-35086:WARNING: chmod of /u01/app/oraInventory

Adding read,write permissions for group.

,Removing read,write,execute permissions for world.

failed!";

Fi    #如果由於某種原因修改失敗,就提示之

$ECHO "Changing groupname of /u01/app/oraInventory to oinstall.";

$CHGRP -R oinstall /u01/app/oraInventory;     #修改/u01/app/oraInventory的組為oinstall

if [ $? != 0 ]; then

$ECHO "OUI-10057:WARNING: chgrp of /u01/app/oraInventory to oinstall failed!";

fi   #失敗提示

$ECHO "The execution of the script is complete."

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29496899/viewspace-1461562/,如需轉載,請註明出處,否則將追究法律責任。