[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/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/29496899/viewspace-1461562/