重新發現Oracle太美之orainstRoot.sh
我們安裝數據庫軟件的時候,都要會執行orainstRoot.sh,今天就來仔細看看這個腳本是來干嘛的。
平台為RedHat 6.4 x64位的,數據庫版本為11.2.0.4.2
下面是腳本的內容
[oracle@rh64 ~]$ cd /u01/app/oraInventory/
[oracle@rh64 oraInventory]$ ls -ltr
total 24
drwxrwx--- 2 oracle oinstall 4096 Oct 30 2013 ContentsXML
-rwxrwx--- 1 oracle oinstall 1620 Oct 30 2013 orainstRoot.sh
-rw-rw---- 1 oracle oinstall 56 Oct 30 2013 oraInst.loc
drwxrwx--- 3 oracle oinstall 4096 May 14 02:47 backup
drwxrwx--- 2 oracle oinstall 4096 May 14 03:16 logs
drwxrwx--- 2 oracle oinstall 4096 May 15 00:27 oui
[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
RUID=`/usr/bin/id|$AWK -F\( '{print $1}'|$AWK -F\= '{print $2}'`
if [ ${RUID} != "0" ];then
$ECHO "This script must be executed as root"
exit 1
fi
----->>>這裡會首先校驗權限,看看是不是以root用戶執行的,如果不是就退出
if [ -d "/etc" ]; then
$CHMOD 755 /etc;
else
$MKDIR -p /etc;
fi
if [ -f "/u01/app/oraInventory/oraInst.loc" ]; then
$CP /u01/app/oraInventory/oraInst.loc /etc/oraInst.loc;
$CHMOD 644 /etc/oraInst.loc
else
INVPTR=/etc/oraInst.loc
INVLOC=/u01/app/oraInventory
GRP=oinstall
PTRDIR="`dirname $INVPTR`";
----->>>如果Central Inventory存在的話,即上面的oraInst.loc,就會復制一份到/etc/下面,作為Central Inventory Pointer File,從名字上就能知道,
這個是Central Inventory的Pointed File
# Create the software inventory location pointer file
if [ ! -d "$PTRDIR" ]; then
$MKDIR -p $PTRDIR;
fi
$ECHO "Creating the Oracle inventory pointer file ($INVPTR)";
$ECHO inventory_loc=$INVLOC > $INVPTR
$ECHO inst_group=$GRP >> $INVPTR
chmod 644 $INVPTR
# Create the inventory directory if it doesn't exist
if [ ! -d "$INVLOC" ];then
$ECHO "Creating the Oracle inventory directory ($INVLOC)";
$MKDIR -p $INVLOC;
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;
----->>>>對於這個目錄,組要有讀寫權限,宿主要有讀寫執行的權限
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;
----->>>注意這裡的組是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."
[oracle@rh64 oraInventory]$
從上面看到,這個腳本無非就是創建oraInst.loc,然後給這個產品目錄修改權限,注意組權限是讀寫,宿主為777,oraInventory的組要是oinstall
其他也沒有多少東西。知道干嘛的就行了,學會了就沒啥了,哪裡報錯哪裡重新檢查就OK了。