首页 > 数据库 >oracle12.2.0.1交互快速部署脚本(shell)

oracle12.2.0.1交互快速部署脚本(shell)

时间:2025-01-13 11:12:09浏览次数:1  
标签:shell file 0.1 db echo install oracle response oracle12.2

背景

有些项目会用到oracle,以前大佬写的脚本不好用,拿来改一改,能用起来先,回头再适配更高版本的oracle。如果使用过程中有什么问题,还请批评指正。

脚本

#!/bin/bash
####################  Steup 1 Install oracle software ####################
#script_name: oracle12.2.0.1_install.sh
#Author: Ahai.Chen
#Email:chenjf_xm@163.com
#auto_install_oracle12c version=12.2.0.1
# attentions1:
# 1.上传12c软件安装包至随意路径下,脚本提示路径是 /opt
#
# linuxx64_12201_database.zip
#
# 2.预设oracle用户的密码为 Ahai.com 请根据需要修改
#####################################
#ORACLE_OS_PWD=                     #
#if [ "$ORACLE_OS_PWD" = "" ]; then #
#    ORACLE_OS_PWD="Ahai.com"   #
#fi                                 #
#####################################
# 3.执行
# chmod + oracle12.2.0.1_install.sh
# sh -x oracle12.2.0.1_install.sh
#
#################### Steup 2 Install oracle listener & dbca  ####################
# attentions2:
########################################
# 1.according to the different environment to set the processes && sessions value
# alter system set processes=500 scope=spfile;
# alter system set sessions=555 scope=spfile;
# 2.ignore these warnings
# /u01/database/response/netca.rsp:LINE30: [GENERAL]: command not found
# /u01/database/response/netca.rsp:LINE62: [oracle.net.ca]: command not found
########################################
export PATH=$PATH
#Source function library.
. /etc/init.d/functions

#Require root to run this script.
uid=`id | cut -d\( -f1 | cut -d= -f2`
if [ $uid -ne 0 ];then
  action "Please run this script as root." /bin/false
  exit 1
fi

##set oracle password
ORACLE_OS_PWD=
if [ "$ORACLE_OS_PWD" = "" ]; then
    ORACLE_OS_PWD="Ahai.com"
fi

###自行判断时钟源源是否正常,正常才会继续开始安装依赖包
read -p "请自行判断时钟源同步是否正常,正常才会继续,请输入 [y/Y/yes/n/N/no]: " timeconfirm && \
[[ $timeconfirm =~ ^[yY]([eE][sS])?$ ]] || { echo "退出,请同步好时钟源为北京时间再来"; exit 0; }

###自行判断yum源是否正常,正常才会继续开始安装依赖包
read -p "请自行判断yum源是否正常,正常才会继续,请输入 [y/Y/yes/n/N/no]: " yumconfirm && \
[[ $yumconfirm =~ ^[yY]([eE][sS])?$ ]] || { echo "退出,请准备好yum源再来"; exit 0; }
echo "start to install require packages..."


###install require packages
echo -e "\033[34mInstallNotice >>\033[0m \033[32moracle install dependency \033[05m...\033[0m"
yum -y install binutils compat-libcap1 compat-libstdc++-33 compat-libstdc++-33*i686 compat-libstdc++-33*.devel \
  compat-libstdc++-33 compat-libstdc++-33*.devel elfutils-libelf elfutils-libelf-devel gcc gcc-c++ \
  glibc glibc*.i686 glibc-devel glibc-devel*.i686 ksh libaio libaio*.i686 libaio-devel libaio-devel*.devel \
  libgcc libgcc*.i686 libstdc++ libstdc++*.i686 libstdc++-devel libstdc++-devel*.devel libXi libXi*.i686 \
  libXtst libXtst*.i686 make sysstat unixODBC unixODBC*.i686 unixODBC-devel unixODBC-devel*.i686 zip unzip tree \
  vim lrzsz epel-release net-tools wget ntpdate ntp
if [[ $? == 0 ]];then
  echo -e "\033[34mInstallNotice >>\033[0m \033[32myum install dependency successed\033[0m"
else
  echo -e "\033[34mInstallNotice >>\033[0m \033[32myum install dependency faild, pls check your network\033[0m"
  exit
fi


###set firewalld & optimize the os system & set selinux
echo "################# Optimize system parameters  ##########################"
firewall_status=`systemctl status firewalld | grep Active |awk '{print $3}'`
if [ ${firewall_status} == "(running)" ];then
  firewall-cmd --permanent --zone=public --add-port=1521/tcp && firewall-cmd --reload
else
  systemctl start firewalld
  firewall-cmd --permanent --zone=public --add-port=1521/tcp && firewall-cmd --reload
fi
echo "[  OK  ] 在firewall上开放1521端口完成"

SELINUX=`cat /etc/selinux/config |grep ^SELINUX=|awk -F '=' '{print $2}'`
if [ ${SELINUX} == "enforcing" ];then
  sed -i "s@SELINUX=enforcing@SELINUX=disabled@g" /etc/selinux/config
else
  if [ ${SELINUX} == "permissive" ];then
    sed -i "s@SELINUX=permissive@SELINUX=disabled@g" /etc/selinux/config
  fi
fi
setenforce 0
echo "[  OK  ] 更改selinux为disabled完成"

echo "================更改为中文字符集================="
  \cp /etc/locale.conf  /etc/locale.conf.$(date +%F)
#cat >>/etc/locale.conf<<EOF
#LANG="zh_CN.UTF-8"
##LANG="en_US.UTF-8"
#EOF
sudo sed -i -E '/^LANG=/s|^|#|; /^#LANG="zh_CN\.UTF-8"/s/^#//; /^LANG=/!b; s/.*/LANG="zh_CN.UTF-8"/' /etc/locale.conf
#正则匹配规则解释
#sudo sed -i -E \
#  -e '/^LANG=/s|^|#|' \                    # 注释掉所有 LANG= 开头的行
#  -e '/^#LANG="zh_CN\.UTF-8"/s/^#//' \    # 取消注释 zh_CN.UTF-8 的行
#  -e '/^LANG=/!b' \                        # 如果不是 LANG= 开头的行,跳过后面的命令
#  -e 's/.*/LANG="zh_CN.UTF-8"/'            # 将匹配到的行替换为 LANG="zh_CN.UTF-8"
#/etc/locale.conf
#为了确保即使没有找到未注释的LANG="zh_CN.UTF-8"设置,它也会被正确添加到文件中,再加一条检查和追加
grep -q '^LANG="zh_CN.UTF-8"$' /etc/locale.conf || echo 'LANG="zh_CN.UTF-8"' | sudo tee -a /etc/locale.conf > /dev/null
source /etc/locale.conf
grep -q '^LANG="zh_CN.UTF-8"$' /etc/locale.conf && \
echo "[  OK  ] 更改字符集zh_CN.UTF-8完成" || \
echo "[FAILED] 更改字符集zh_CN.UTF-8未成功完成"

###set the ip in hosts
echo "############################   Ip&Hosts Configuration  #######################################"
hostname=`hostname`
HostIP=`ip a|grep 'inet '|grep -v '127.0.0.1'|awk '{print $2}'|awk -F '/' '{print $1}'`
for i in ${HostIP}
do
    A=`grep "${i}" /etc/hosts`
    if [ ! -n "${A}" ];then
        echo "${i} ${hostname}" >> /etc/hosts 
    else
        break
    fi
done
cat /etc/hosts 
echo "[  OK  ] 主机名和ip加入/etc/hosts完成"

###create group&user
echo "############################   Create Group&User  #######################################"
ora_user=oracle
ora_group=('oinstall' 'dba' 'oper')
for i in ${ora_group[@]}
do
    B=`grep '${i}' /etc/group`
    if [ ! -n ${B} ];then
        groupdel ${i} && groupadd ${i}
    else    
        groupadd ${i}
    fi
done
echo "[  OK  ] 'oinstall' 'dba' 'oper' 组创建完成"

C=`grep 'oracle' /etc/passwd`
if [ ! -n ${C} ];then
    userdel -r ${ora_user} && useradd -u 501 -g ${ora_group[0]} -G ${ora_group[1]},${ora_group[2]} ${ora_user}
else
    useradd -u 501 -g ${ora_group[0]} -G ${ora_group[1]},${ora_group[2]} ${ora_user}
fi
echo "${ORACLE_OS_PWD}" | passwd --stdin ${ora_user}
echo "[  OK  ] 'oracle' 系统用户创建完成,设置密码为${ORACLE_OS_PWD}"


<<!
ORACLE_SID=upp
ORACLE_BASE=/apps/oracle/oracle
ORACLE_HOME=/apps/oracle/oracle/product/12c/dbhome_1
!



###create directory and grant priv
echo "############################ Create DIR & set privileges & set OracleSid ##################"
echo "############################   Create OracleBaseDi #######################################"
echo "############################   Create OracleHomeDir #######################################"
count=0
while [ $count -lt 3 ]
do
    read -p "Please input the ORACLE_SID(e.g:orcl):" S1
    read -p "Please input the ORACLE_SID again(e.g:orcl):" S2
    if [ "${S1}" == "${S2}" ];then
        export ORACLE_SID=${S1}
        break
    else
        echo "You input ORACLE_SID not same."
        count=$[${count}+1]
    fi
done

count=0
while [ $count -lt 3 ]
do
        read -p "Please input the ORACLE_BASE(e.g:/u01/oracle):" S1
        read -p "Please input the ORACLE_BASE again(e.g:/u01/oracle):" S2
        if [ "${S1}" == "${S2}" ];then
                export ORACLE_BASE=${S1}
                break
        else    
                echo "You input ORACLE_BASE not same."
                count=$[${count}+1]
        fi 
done

count=0
while [ $count -lt 3 ]
do
        read -p "Please input the ORACLE_HOME(e.g:/u01/oracle/product/12c/dbhome_1):" S1
        read -p "Please input the ORACLE_HOME again(e.g:/u01/oracle/product/12c/dbhome_1):" S2
        if [ "${S1}" == "${S2}" ];then
                export ORACLE_HOME=${S1}
                break
        else        
                echo "You input ORACLE_HOME not same."
                count=$[${count}+1]
        fi      
done

if [ ! -d ${ORACLE_HOME} ];then
    mkdir -p ${ORACLE_HOME}
fi
if [ ! -d ${ORACLE_BASE}/data ];then
    mkdir -p ${ORACLE_BASE}/data
fi
if [ ! -d ${ORACLE_BASE}/recovery ];then
    mkdir -p ${ORACLE_BASE}/recovery
fi
echo "[  OK  ] ORACLE_SID实例名${ORACLE_SID}确认完成"
echo "[  OK  ] ORACLE_BASE路径${ORACLE_BASE}确认完成并完成目录创建"
echo "[  OK  ] ORACLE_HOME路径${ORACLE_HOME}确认完成并完成目录创建"
echo "[  OK  ] ORACLE数据路径${ORACLE_BASE}/data确认完成并完成目录创建"
echo "[  OK  ] ORACLE归档路径${ORACLE_BASE}/recovery确认完成并完成目录创建"

#ORACLE_BASE的上一级目录(比如u01)
ora_dir=`echo ${ORACLE_BASE}|awk -F '/' '{print $2}'`

###set the sysctl,limits and profile
echo "############################   Configure environment variables #######################################"

egrep -q "^\s*kernel\.shmmax\s*.+(\s*#.*)?\s*$" /etc/sysctl.conf && sed -ri "s/^\s*kernel\.shmmax\s*.+(\s*#.*)?\s*$/kernel.shmmax = 68719476736/" /etc/sysctl.conf || echo "kernel.shmmax = 68719476736" >> /etc/sysctl.conf
egrep -q "^\s*kernel\.shmmni\s*.+(\s*#.*)?\s*$" /etc/sysctl.conf && sed -ri "s/^\s*kernel\.shmmni\s*.+(\s*#.*)?\s*$/kernel.shmmni = 4096/" /etc/sysctl.conf || echo "kernel.shmmni = 4096" >> /etc/sysctl.conf
egrep -q "^\s*kernel\.shmall\s*.+(\s*#.*)?\s*$" /etc/sysctl.conf && sed -ri "s/^\s*kernel\.shmall\s*.+(\s*#.*)?\s*$/kernel.shmall = 16777216/" /etc/sysctl.conf || echo "kernel.shmall = 16777216" >> /etc/sysctl.conf
egrep -q "^\s*kernel\.sem\s*.+(\s*#.*)?\s*$" /etc/sysctl.conf && sed -ri "s/^\s*kernel\.sem\s*.+(\s*#.*)?\s*$/kernel.sem = 1010 129280 1010 128/" /etc/sysctl.conf || echo "kernel.sem = 1010 129280 1010 128" >> /etc/sysctl.conf
egrep -q "^\s*net\.ipv4\.ip_local_port_range\s*.+(\s*#.*)?\s*$" /etc/sysctl.conf && sed -ri "s/^\s*net\.ipv4\.ip_local_port_range\s*.+(\s*#.*)?\s*$/net.ipv4.ip_local_port_range = 5000 65000/" /etc/sysctl.conf || echo "net.ipv4.ip_local_port_range = 5000 65000" >> /etc/sysctl.conf
egrep -q "^\s*net\.core\.rmem_default\s*.+(\s*#.*)?\s*$" /etc/sysctl.conf && sed -ri "s/^\s*net\.core\.rmem_default\s*.+(\s*#.*)?\s*$/net.core.rmem_default = 4194304/" /etc/sysctl.conf || echo "net.core.rmem_default = 4194304" >> /etc/sysctl.conf
egrep -q "^\s*net\.core\.rmem_max\s*.+(\s*#.*)?\s*$" /etc/sysctl.conf && sed -ri "s/^\s*net\.core\.rmem_max\s*.+(\s*#.*)?\s*$/net.core.rmem_max = 4194304/" /etc/sysctl.conf || echo "net.core.rmem_max = 4194304" >> /etc/sysctl.conf
egrep -q "^\s*net\.core\.wmem_default\s*.+(\s*#.*)?\s*$" /etc/sysctl.conf && sed -ri "s/^\s*net\.core\.wmem_default\s*.+(\s*#.*)?\s*$/net.core.wmem_default = 262144/" /etc/sysctl.conf || echo "net.core.wmem_default = 262144" >> /etc/sysctl.conf
egrep -q "^\s*net\.core\.wmem_max\s*.+(\s*#.*)?\s*$" /etc/sysctl.conf && sed -ri "s/^\s*net\.core\.wmem_max\s*.+(\s*#.*)?\s*$/net.core.wmem_max = 1048576/" /etc/sysctl.conf || echo "net.core.wmem_max = 1048576" >> /etc/sysctl.conf
egrep -q "^\s*fs\.aio-max-nr\s*.+(\s*#.*)?\s*$" /etc/sysctl.conf && sed -ri "s/^\s*fs\.aio-max-nr\s*.+(\s*#.*)?\s*$/fs.aio-max-nr = 1048576/" /etc/sysctl.conf || echo "fs.aio-max-nr = 1048576" >> /etc/sysctl.conf
egrep -q "^\s*fs\.file-max\s*.+(\s*#.*)?\s*$" /etc/sysctl.conf && sed -ri "s/^\s*fs\.file-max\s*.+(\s*#.*)?\s*$/fs.file-max = 6815744/" /etc/sysctl.conf || echo "fs.file-max = 6815744" >> /etc/sysctl.conf

/sbin/sysctl -p
echo "[  OK  ] sysctl内核配置完成"

set_limits () {
declare -A limits=(
    ["oracle soft nproc"]="16384"
    ["oracle hard nproc"]="16384"
    ["oracle soft nofile"]="65536"
    ["oracle hard nofile"]="65536"
    ["oracle soft memlock"]="4000000"
    ["oracle hard memlock"]="4000000"
)

for limit in "${!limits[@]}"; do
    value=${limits[$limit]}
    egrep -q "^\\s*${limit//\//\\/}\\s+.+(\s*#.*)?\$" /etc/security/limits.conf && \
        sed -ri "s/^\\s*${limit//\//\\/}\\s+.+(\s*#.*)?\$/$(echo $limit | sed 's/\//\\\//g') $value/" /etc/security/limits.conf || \
        echo "$limit $value" | sudo tee -a /etc/security/limits.conf > /dev/null
done
echo "[  OK  ] /etc/security/limits.conf配置完成"
}
set_limits

set_profile () {
F=`grep 'ORACLE_SID' /home/${ora_user}/.bash_profile`
if [ ! -n "${F}" ];then
cat << EOF >> /home/${ora_user}/.bash_profile
export ORACLE_SID=${ORACLE_SID}
export ORACLE_BASE=${ORACLE_BASE}
export ORACLE_HOME=${ORACLE_HOME}
export PATH=\$PATH:\$ORACLE_HOME/bin
EOF
else
    tail -4 /home/${ora_user}/.bash_profile
fi

G=`grep 'oracle' /etc/profile`
if [ ! -n "${G}" ];then
cat << EOF >> /etc/profile
if [ \$USER = "oracle" ];then
    if [ \$SHELL = "/bin/ksh" ];then
        ulimit -p 16384
        ulimit -n 65536
    else
        ulimit -u 16384 -n 65536
    fi
fi
EOF
else
    tail -8 /etc/profile
fi
echo "[  OK  ] oracle环境变量bash_profile和全局变量profile配置完成"
}
set_profile



###unzip the install package and set response file
echo "############################   unzip the install package  #######################################"
unzip_package () {
count=0
while [ $count -lt 3 ]
do
    read -p "Please input the zip file location(e.g:/opt/linuxx64_12201_database.zip):" zfileone
    if [ ! -f ${zfileone} ];then
        echo "You input location not found zip file."
        count=$[${count}+1]
    else
        export zfileone=${zfileone}
        break
    fi
done

if [ ! -d /${ora_dir}/database ];then 
    unzip ${zfileone} -d /${ora_dir}
else
    echo "发现安装目录下有解压包"
    read -p "是否删除重新解压,请输入 [y/Y/yes/n/N/no]: " pgkcheck && \
    if [[ $pgkcheck =~ ^[yY]([eE][sS])?$ ]]; then
        # 如果用户选择了 'y', 'Y', 'yes' 或 'YES'
        echo "正在删除旧的解压文件并重新解压..."
        rm -rf "/${ora_dir}/database"
        unzip "${zfileone}" -d "/${ora_dir}"
    else
        # 如果用户选择了其他选项
        echo "ok,不删除,沿用之前解压的安装包继续安装"
    fi
fi

chown -R ${ora_user}:${ora_group[0]}  /${ora_dir} && chmod -R 775 /${ora_dir}
}

unzip_package
echo "[  OK  ] 解压安装包${zfileone}完成"


###set Oracle install.db.starterdb installSysPassword
echo "############################   set installSysPassword  #######################################"
count=0
while [ $count -lt 3 ]
do
        read -p "Please input the installSysPassword(e.g:orcl20200202):" S1
        read -p "Please input the installSysPassword again(orcl20200202):" S2
        if [ "${S1}" == "${S2}" ];then
                export installSysPassword=${S1}
                break
        else        
                echo "You input installSysPassword not same."
                count=$[${count}+1]
        fi      
done
echo "[  OK  ] 安装系统密码配置完成"

#installSysPassword=Oracle20241211
###set Response File
echo "############################   set ResponseFile  #######################################"
free_m=`free -m | grep 'Mem:'|awk '{print $2}'`
db_response_file=`find /${ora_dir} -type f -name db_install.rsp`
data_dir=${ORACLE_BASE}/data
recovery_dir=${ORACLE_BASE}/recovery
db_response_file_path=`find / -type f -name db_install.rsp | sed -n 's:/[^/]*$::p'`

install_dir=${db_response_file_path%/*}

MEM=`free -m|grep 'Mem:'|awk '{print $2}'`
TOTAL=$[MEM*8/10]
echo "The memory size of this server is ${MEM}M,Suggest setting 80% of the server to Oracle, such as ${TOTAL}"


select_memory_size() {
    echo "请选择内存大小:"
    echo "1. 1024 MB"
    echo "2. 2048 MB"
    echo "3. 5120 MB"
    echo "4. 8192 MB"
    echo "5. 自定义输入 (MB)"
    
    read -p "请输入选项 [1-5]: " option
    
    case $option in
        1) Memory=1024 ;;
        2) Memory=2048 ;;
        3) Memory=5120 ;;
        4) Memory=8192 ;;
        5) 
            read -p "Please enter a custom memory size (MB): " custom_memory
            # 检查输入是否为正整数
            if ! [[ "$custom_memory" =~ ^[0-9]+$ ]]; then
                echo "错误: 输入不是一个有效的正整数."
                exit 1
            fi
            Memory=$custom_memory
            ;;
        *) echo "无效选项"; exit 1 ;;
    esac
    
    echo "The memory size you have chosen is: ${Memory} MB"
}

select_memory_size
echo "[  OK  ] 内存大小配置完成"





#cd `find / -type f -name db_install.rsp | sed -n 's:/[^/]*$::p'` && cd ../
#install_dir=`pwd`
egrep -q "^\s*oracle\.install\.option\s*.+(\s*#.*)?\s*$" ${db_response_file} && sed -ri "s/^\s*oracle\.install\.option\s*.+(\s*#.*)?\s*$/oracle.install.option=INSTALL_DB_SWONLY/" ${db_response_file} || echo "oracle.install.option=INSTALL_DB_SWONLY" >> ${db_response_file}
egrep -q "^\s*UNIX_GROUP_NAME\s*.+(\s*#.*)?\s*$" ${db_response_file} && sed -ri "s/^\s*UNIX_GROUP_NAME\s*.+(\s*#.*)?\s*$/UNIX_GROUP_NAME=${ora_group[0]}/" ${db_response_file} || echo "UNIX_GROUP_NAME=${ora_group[0]}" >> ${db_response_file}
egrep -q "^\s*INVENTORY_LOCATION\s*.+(\s*#.*)?\s*$" ${db_response_file} && sed -ri "s|^\s*INVENTORY_LOCATION\s*.+(\s*#.*)?\s*$|INVENTORY_LOCATION=${ORACLE_BASE}\/oraInventory|" ${db_response_file} || echo "INVENTORY_LOCATION=${ORACLE_BASE}/oraInventory" >> ${db_response_file}
egrep -q "^\s*ORACLE_HOME\s*.+(\s*#.*)?\s*$" ${db_response_file} && sed -ri "s|^\s*ORACLE_HOME\s*.+(\s*#.*)?\s*$|ORACLE_HOME=${ORACLE_HOME}|" ${db_response_file} || echo "ORACLE_HOME=${ORACLE_HOME}" >> ${db_response_file}
egrep -q "^\s*ORACLE_BASE\s*.+(\s*#.*)?\s*$" ${db_response_file} && sed -ri "s|^\s*ORACLE_BASE\s*.+(\s*#.*)?\s*$|ORACLE_BASE=${ORACLE_BASE}|" ${db_response_file} || echo "ORACLE_BASE=${ORACLE_BASE}" >> ${db_response_file}


#oracle.install.option=INSTALL_DB_SWONLY
#UNIX_GROUP_NAME=oinstall
#INVENTORY_LOCATION=/apps/oracle/oracle/oraInventory
#ORACLE_HOME=/apps/oracle/oracle/product/12c/dbhome_1
#ORACLE_BASE=/apps/oracle/oracle


#sed -i "s!ORACLE_HOSTNAME=!ORACLE_HOSTNAME=${hostname}!g" ${db_response_file}
#sed -i "s!SELECTED_LANGUAGES=en!SELECTED_LANGUAGES=en,zh_CN!g" ${db_response_file}


egrep -q "^\s*oracle\.install\.db\.InstallEdition\s*.+(\s*#.*)?\s*$" ${db_response_file} && sed -ri "s/^\s*oracle\.install\.db\.InstallEdition\s*.+(\s*#.*)?\s*$/oracle.install.db.InstallEdition=EE/" ${db_response_file} || echo "oracle.install.db.InstallEdition=EE" >> ${db_response_file}
egrep -q "^\s*oracle\.install\.db\.OSDBA_GROUP\s*.+(\s*#.*)?\s*$" ${db_response_file} && sed -ri "s/^\s*oracle\.install\.db\.OSDBA_GROUP\s*.+(\s*#.*)?\s*$/oracle.install.db.OSDBA_GROUP=${ora_group[1]}/" ${db_response_file} || echo "oracle.install.db.OSDBA_GROUP=${ora_group[1]}" >> ${db_response_file}
egrep -q "^\s*oracle\.install\.db\.OSOPER_GROUP\s*.+(\s*#.*)?\s*$" ${db_response_file} && sed -ri "s/^\s*oracle\.install\.db\.OSOPER_GROUP\s*.+(\s*#.*)?\s*$/oracle.install.db.OSOPER_GROUP=${ora_group[2]}/" ${db_response_file} || echo "oracle.install.db.OSOPER_GROUP=${ora_group[2]}" >> ${db_response_file}
egrep -q "^\s*oracle\.install\.db\.OSBACKUPDBA_GROUP\s*.+(\s*#.*)?\s*$" ${db_response_file} && sed -ri "s/^\s*oracle\.install\.db\.OSBACKUPDBA_GROUP\s*.+(\s*#.*)?\s*$/oracle.install.db.OSBACKUPDBA_GROUP=${ora_group[1]}/" ${db_response_file} || echo "oracle.install.db.OSBACKUPDBA_GROUP=${ora_group[1]}" >> ${db_response_file}
egrep -q "^\s*oracle\.install\.db\.OSDGDBA_GROUP\s*.+(\s*#.*)?\s*$" ${db_response_file} && sed -ri "s/^\s*oracle\.install\.db\.OSDGDBA_GROUP\s*.+(\s*#.*)?\s*$/oracle.install.db.OSDGDBA_GROUP=${ora_group[1]}/" ${db_response_file} || echo "oracle.install.db.OSDGDBA_GROUP=${ora_group[1]}" >> ${db_response_file}
egrep -q "^\s*oracle\.install\.db\.OSKMDBA_GROUP\s*.+(\s*#.*)?\s*$" ${db_response_file} && sed -ri "s/^\s*oracle\.install\.db\.OSKMDBA_GROUP\s*.+(\s*#.*)?\s*$/oracle.install.db.OSKMDBA_GROUP=${ora_group[1]}/" ${db_response_file} || echo "oracle.install.db.OSKMDBA_GROUP=${ora_group[1]}" >> ${db_response_file}
egrep -q "^\s*oracle\.install\.db\.OSRACDBA_GROUP\s*.+(\s*#.*)?\s*$" ${db_response_file} && sed -ri "s/^\s*oracle\.install\.db\.OSRACDBA_GROUP\s*.+(\s*#.*)?\s*$/oracle.install.db.OSRACDBA_GROUP=${ora_group[1]}/" ${db_response_file} || echo "oracle.install.db.OSRACDBA_GROUP=${ora_group[1]}" >> ${db_response_file}

#oracle.install.db.OSDBA_GROUP=dba
#oracle.install.db.OSOPER_GROUP=oper
#oracle.install.db.OSBACKUPDBA_GROUP=dba
#oracle.install.db.OSDGDBA_GROUP=dba
#oracle.install.db.OSKMDBA_GROUP=dba
#oracle.install.db.OSRACDBA_GROUP=dba


egrep -q "^\s*oracle\.install\.db\.config\.starterdb\.type\s*.+(\s*#.*)?\s*$" ${db_response_file} && sed -ri "s/^\s*oracle\.install\.db\.config\.starterdb\.type\s*.+(\s*#.*)?\s*$/oracle.install.db.config.starterdb.type=GENERAL_PURPOSE/" ${db_response_file} || echo "oracle.install.db.config.starterdb.type=GENERAL_PURPOSE" >> ${db_response_file}
egrep -q "^\s*oracle\.install\.db\.config\.starterdb\.globalDBName\s*.+(\s*#.*)?\s*$" ${db_response_file} && sed -ri "s/^\s*oracle\.install\.db\.config\.starterdb\.globalDBName\s*.+(\s*#.*)?\s*$/oracle.install.db.config.starterdb.globalDBName=${ORACLE_SID}/" ${db_response_file} || echo "oracle.install.db.config.starterdb.globalDBName=${ORACLE_SID}" >> ${db_response_file}
egrep -q "^\s*oracle\.install\.db\.config\.starterdb\.SID\s*.+(\s*#.*)?\s*$" ${db_response_file} && sed -ri "s/^\s*oracle\.install\.db\.config\.starterdb\.SID\s*.+(\s*#.*)?\s*$/oracle.install.db.config.starterdb.SID=${ORACLE_SID}/" ${db_response_file} || echo "oracle.install.db.config.starterdb.SID=${ORACLE_SID}" >> ${db_response_file}


#oracle.install.db.config.starterdb.type=GENERAL_PURPOSE
#oracle.install.db.config.starterdb.globalDBName=${ORACLE_SID}
#oracle.install.db.config.starterdb.SID=${ORACLE_SID}


egrep -q "^\s*oracle\.install\.db\.config\.starterdb\.characterSet\s*.+(\s*#.*)?\s*$" ${db_response_file} && sed -ri "s/^\s*oracle\.install\.db\.config\.starterdb\.characterSet\s*.+(\s*#.*)?\s*$/oracle.install.db.config.starterdb.characterSet=ZHS16GBK/" ${db_response_file} || echo "oracle.install.db.config.starterdb.characterSet=ZHS16GBK" >> ${db_response_file}
egrep -q "^\s*oracle\.install\.db\.config\.starterdb\.memoryOption\s*.+(\s*#.*)?\s*$" ${db_response_file} && sed -ri "s/^\s*oracle\.install\.db\.config\.starterdb\.memoryOption\s*.+(\s*#.*)?\s*$/oracle.install.db.config.starterdb.memoryOption=true/" ${db_response_file} || echo "oracle.install.db.config.starterdb.memoryOption=true" >> ${db_response_file}
egrep -q "^\s*oracle\.install\.db\.config\.starterdb\.memoryLimit\s*.+(\s*#.*)?\s*$" ${db_response_file} && sed -ri "s/^\s*oracle\.install\.db\.config\.starterdb\.memoryLimit\s*.+(\s*#.*)?\s*$/oracle.install.db.config.starterdb.memoryLimit=${Memory}/" ${db_response_file} || echo "oracle.install.db.config.starterdb.memoryLimit=${Memory}" >> ${db_response_file}



#oracle.install.db.config.starterdb.characterSet=ZHS16GBK
#oracle.install.db.config.starterdb.memoryOption=true
#oracle.install.db.config.starterdb.memoryLimit=${Memory}

egrep -q "^\s*oracle\.install\.db\.config\.starterdb\.password\.ALL\s*.+(\s*#.*)?\s*$" ${db_response_file} && sed -ri "s/^\s*oracle\.install\.db\.config\.starterdb\.password\.ALL\s*.+(\s*#.*)?\s*$/oracle.install.db.config.starterdb.password.ALL=${installSysPassword}/" ${db_response_file} || echo "oracle.install.db.config.starterdb.password.ALL=${installSysPassword}" >> ${db_response_file}
egrep -q "^\s*oracle\.install\.db\.config\.starterdb\.storageType\s*.+(\s*#.*)?\s*$" ${db_response_file} && sed -ri "s/^\s*oracle\.install\.db\.config\.starterdb\.storageType\s*.+(\s*#.*)?\s*$/oracle.install.db.config.starterdb.storageType=FILE_SYSTEM_STORAGE/" ${db_response_file} || echo "oracle.install.db.config.starterdb.storageType=FILE_SYSTEM_STORAGE" >> ${db_response_file}
egrep -q "^\s*oracle\.install\.db\.config\.starterdb\.fileSystemStorage\.dataLocation\s*.+(\s*#.*)?\s*$" ${db_response_file} && sed -ri "s|^\s*oracle\.install\.db\.config\.starterdb\.fileSystemStorage\.dataLocation\s*.+(\s*#.*)?\s*$|oracle.install.db.config.starterdb.fileSystemStorage.dataLocation=${data_dir}|" ${db_response_file} || echo "oracle.install.db.config.starterdb.fileSystemStorage.dataLocation=${data_dir}" >> ${db_response_file}
egrep -q "^\s*oracle\.install\.db\.config\.starterdb\.fileSystemStorage\.recoveryLocation\s*.+(\s*#.*)?\s*$" ${db_response_file} && sed -ri "s|^\s*oracle\.install\.db\.config\.starterdb\.fileSystemStorage\.recoveryLocation\s*.+(\s*#.*)?\s*$|oracle.install.db.config.starterdb.fileSystemStorage.recoveryLocation=${recovery_dir}|" ${db_response_file} || echo "oracle.install.db.config.starterdb.fileSystemStorage.recoveryLocation=${recovery_dir}" >> ${db_response_file}



#oracle.install.db.config.starterdb.password.ALL=Oracle20241211
#oracle.install.db.config.starterdb.storageType=FILE_SYSTEM_STORAGE
#oracle.install.db.config.starterdb.fileSystemStorage.dataLocation=/apps/oracle/oracle/data
#oracle.install.db.config.starterdb.fileSystemStorage.recoveryLocation=/apps/oracle/oracle/recovery


egrep -q "^\s*SECURITY_UPDATES_VIA_MYORACLESUPPORT\s*.+(\s*#.*)?\s*$" ${db_response_file} && sed -ri "s/^\s*SECURITY_UPDATES_VIA_MYORACLESUPPORT\s*.+(\s*#.*)?\s*$/SECURITY_UPDATES_VIA_MYORACLESUPPORT=false/" ${db_response_file} || echo "SECURITY_UPDATES_VIA_MYORACLESUPPORT=false" >> ${db_response_file}
egrep -q "^\s*DECLINE_SECURITY_UPDATES\s*.+(\s*#.*)?\s*$" ${db_response_file} && sed -ri "s/^\s*DECLINE_SECURITY_UPDATES\s*.+(\s*#.*)?\s*$/DECLINE_SECURITY_UPDATES=true/" ${db_response_file} || echo "DECLINE_SECURITY_UPDATES=true" >> ${db_response_file}



#SECURITY_UPDATES_VIA_MYORACLESUPPORT=false
#DECLINE_SECURITY_UPDATES=true


#sed -i "s!oracle.installer.autoupdates.option=!oracle.installer.autoupdates.option=SKIP_UPDATES!g" ${db_response_file}

echo "[  OK  ] ${db_response_file}配置完成"

###starting to install oracle software
echo "############################   Oracle Installing  #######################################"
oracle_out='/tmp/oracle.out'
touch ${oracle_out}
chown ${ora_user}:${ora_group[0]} ${oracle_out}
#su - oracle -c "${install_dir}/runInstaller -silent -ignoreDiskWarning -ignoreSysPrereqs -ignorePrereq -responseFile ${db_response_file}" > ${oracle_out} 2>&1
su - oracle -c "${install_dir}/runInstaller -silent -ignoreSysPrereqs -ignorePrereq -responseFile ${db_response_file}" > ${oracle_out} 2>&1
echo -e "\033[34mInstallNotice >>\033[0m \033[32moracle install starting \033[05m...\033[0m"
sleep 60
installActionslog=`find /tmp -name installActions*`
echo "You cat check the oracle install log command: tail -100f ${installActionslog}"
while true; do
  grep '[FATAL] [INS-10101]' ${oracle_out} &> /dev/null
  if [[ $? == 0 ]];then
    echo -e "\033[34mInstallNotice >>\033[0m \033[31moracle start install has [ERROR]\033[0m"
    cat ${oracle_out}
    exit
  fi
  sleep 120
  cat /tmp/oracle.out  | grep sh
  if [[ $? == 0 ]];then
    `cat /tmp/oracle.out  | grep sh | awk -F ' ' '{print $2}' | head -1`
    if [[ $? == 0 ]]; then
      echo -e "\033[34mInstallNotice >>\033[0m \033[32mScript orainstRoot.sh run successed\033[0m"
	  `cat /tmp/oracle.out  | grep sh | awk -F ' ' '{print $2}' | tail -1`
        if [[ $? == 0 ]];then
          echo -e "\033[34mInstallNotice >>\033[0m \033[32mScript root.sh  run successed\033[0m"
	      break
        else
          echo -e "\033[34mInstallNotice >>\033[0m \033[31mScript root.sh  run faild\033[0m"
        fi
    else
      echo -e "\033[34mInstallNotice >>\033[0m \033[31mScript orainstRoot.sh run faild\033[0m"
    fi
  fi
done

echo "#######################   Oracle software 安装完成      ##############################"


# install listener && dbca
echo "############################   install oracle listener && dbca  #######################################"
echo "############################   set oracle schema sysPassword  #######################################"
count=0
while [ $count -lt 3 ]
do
        echo "a.Oracle 建议, 输入的口令长度不应少于 8 个字符, 至少包含 1 个大写字符, 1 个小写字符和 1 个数字 [0-9]。"
        echo "b.Oracle建议不要将sid或者其有关的关键字用作口令一部分"	
        read -p "Please input the SYSPASSWORD(e.g:orcl20200202):" S1
        read -p "Please input the SYSPASSWORD again(e.g:orcl20200202):" S2
        if [ "${S1}" == "${S2}" ];then
                export SYSPASSWORD="${S1}"
                break
        else        
                echo "You input SYSPASSWORD not same."
                count=$[${count}+1]
        fi      
done
echo "############################   set oracle app_user  #######################################"
count=0
while [ $count -lt 3 ]
do
        read -p "Please input the USER_NAME(e.g:orcl):" S1
        read -p "Please input the USER_NAME again(e.g:orcl):" S2
        if [ "${S1}" == "${S2}" ];then
                export USER_NAME=${S1}
                break
        else        
                echo "You input USER_NAME not same."
                count=$[${count}+1]
        fi      
done
echo "############################   set oracle app_passwd  #######################################"
count=0
while [ $count -lt 3 ]
do
        echo "a.Oracle 建议, 输入的口令长度不应少于 8 个字符, 至少包含 1 个大写字符, 1 个小写字符和 1 个数字 [0-9]。"
        echo "b.Oracle建议不要将sid或者其有关的关键字用作口令一部分"		
        read -p "Please input the USER_PASSWD(e.g:orcl2020):" S1
        read -p "Please input the USER_PASSWD again(e.g:orcl202):" S2
        if [ "${S1}" == "${S2}" ];then
                export USER_PASSWD="${S1}"
                break
        else        
                echo "You input USER_PASSWD not same."
                count=$[${count}+1]
        fi      
done
echo "############################   set app_user tmp_dbf  #######################################"
count=0
while [ $count -lt 3 ]
do
        read -p "Please input the TMP_DBF(e.g:orcl_temp):" S1
        read -p "Please input the TMP_DBF again(e.g:orcl_temp):" S2
        if [ "${S1}" == "${S2}" ];then
                export TMP_DBF=${S1}
                break
        else        
                echo "You input TMP_DBF not same."
                count=$[${count}+1]
        fi      
done
echo "############################   set app_user data_dbf  #######################################"
count=0
while [ $count -lt 3 ]
do
        read -p "Please input the DATA_DBF(e.g:orcl_data):" S1
        read -p "Please input the DATA_DBF again(e.g:orcl_data):" S2
        if [ "${S1}" == "${S2}" ];then
                export DATA_DBF=${S1}
                break
        else        
                echo "You input DATA_DBF not same."
                count=$[${count}+1]
        fi      
done
ORACLE_SID=`su - oracle -c 'source ~/.bash_profile && echo $ORACLE_SID'`
ORACLE_BASE=`su - oracle -c 'source ~/.bash_profile && echo $ORACLE_BASE'`
ORACLE_HOME=`su - oracle -c 'source ~/.bash_profile && echo $ORACLE_HOME'`
ora_dir=`echo ${ORACLE_BASE}|awk -F '/' '{print $2}'`
DB_SHUT=${ORACLE_HOME}/bin/dbshut
DB_START=${ORACLE_HOME}/bin/dbstart
DATA_DIR=${ORACLE_BASE}/data
BACKUP_DIR=${ORACLE_BASE}/backup

[ ! -f $BACKUP_DIR ] && mkdir $BACKUP_DIR

CDB_SQL="
sqlplus / as sysdba << EOF
create temporary tablespace $TMP_DBF tempfile '$DATA_DIR/$ORACLE_SID/${TMP_DBF}.dbf' size 200m autoextend on next 200m maxsize unlimited extent management local;
create tablespace $DATA_DBF logging datafile '$DATA_DIR/$ORACLE_SID/${DATA_DBF}.dbf' size 20G autoextend on next 512m maxsize unlimited extent management local;
create user $USER_NAME identified by $USER_PASSWD default tablespace $DATA_DBF temporary tablespace $TMP_DBF;
grant connect,resource to $USER_NAME;
grant create view to $USER_NAME;
grant create public synonym to $USER_NAME;
grant drop public synonym to $USER_NAME;
grant unlimited tablespace to $USER_NAME;
create or replace directory dir_dump as '$BACKUP_DIR';
grant read,write on directory dir_dump to $USER_NAME;
ALTER PROFILE DEFAULT LIMIT PASSWORD_LIFE_TIME UNLIMITED;
alter system set processes=500 scope=spfile;
alter system set sessions=572 scope=spfile;
shutdown immediate;
startup mount;
alter database archivelog;
alter database open;
exit
EOF
"

temp=`ls ${ORACLE_BASE}|grep 'data'`
if [ ! -n ${temp} ];then
        mkdir ${ORACLE_BASE}/data
        export DATAFILE=${ORACLE_BASE}/data
else
        export DATAFILE=${ORACLE_BASE}/data
fi
temp=`ls ${ORACLE_BASE}|grep 'area'`
if [ ! -n ${temp} ];then
        mkdir ${ORACLE_BASE}/flash_recovery_area
        export RECOVERY=${ORACLE_BASE}/flash_recovery_area
else
        export RECOVERY=${ORACLE_BASE}/flash_recovery_area
fi
#NETCA=`find / -type f -name netca.rsp`
NETCA=`find /${ora_dir} -type f -name netca.rsp`

netca_response_file=`find /${ora_dir} -type f -name netca.rsp`

#sed -i "s!INSTALL_TYPE=""typical""!INSTALL_TYPE=""custom""!g" ${netca_response_file}

egrep -q "^INSTALL_TYPE\s*.+(\s*#.*)?\s*$" ${netca_response_file} && sed -ri "s|^INSTALL_TYPE\s*.+(\s*#.*)?\s*$|INSTALL_TYPE=\"\"custom\"\"|" ${netca_response_file} || echo "INSTALL_TYPE=\"\"custom\"\"" >> ${netca_response_file}

###set listener&tnsnames
echo "############################   Oracle listener&dbca  #######################################"
su - oracle << EOF
source ~/.bash_profile
${ORACLE_HOME}/bin/netca -silent -responsefile ${netca_response_file}
dbca -silent -createDatabase -templateName General_Purpose.dbc -gdbname ${ORACLE_SID} -sid ${ORACLE_SID} -sysPassword ${SYSPASSWORD} -systemPassword ${SYSPASSWORD} -responseFile NO_VALUE -datafileDestination ${DATAFILE} -redoLogFileSize 1000 -recoveryAreaDestination ${RECOVERY} -storageType FS -characterSet ZHS16GBK -nationalCharacterSet AL16UTF16 -sampleSchema false -totalMemory ${Memory} -databaseType OLTP -emConfiguration NONE
EOF


echo "[  OK  ] Oracle_listener && dbca配置完成"

#${ORACLE_HOME}/bin/netca -silent -responsefile ${netca_response_file}
#dbca -silent -createDatabase -templateName General_Purpose.dbc -gdbname ${ORACLE_SID} -sid ${ORACLE_SID} -sysPassword ${SYSPASSWORD} -systemPassword ${SYSPASSWORD} -responseFile NO_VALUE -datafileDestination ${DATAFILE} -redoLogFileSize 1000 -recoveryAreaDestination ${RECOVERY} -storageType FS -characterSet ZHS16GBK -nationalCharacterSet AL16UTF16 -sampleSchema false -memoryPercentage 80 -totalMemory $TOTAL -databaseType OLTP -emConfiguration NONE


sed -i "s!${ORACLE_SID}:${ORACLE_HOME}:N!${ORACLE_SID}:${ORACLE_HOME}:Y!g" /etc/oratab
egrep -q "^${ORACLE_SID}\s*.+(\s*#.*)?\s*$" /etc/oratab && sed -ri "s|^${ORACLE_SID}\s*.+(\s*#.*)?\s*$|${ORACLE_SID}\:${ORACLE_HOME}\:Y|" /etc/oratab || echo "INSTALL_TYPE=\"\"custom\"\"" >> /etc/oratab
AUTO_START_CONFIG=`cat /etc/oratab|grep ${ORACLE_SID} |awk -F ':' '{print $NF}'`
AUTO_START_CONFIG_expected='Y'

if [ ${AUTO_START_CONFIG} = ${AUTO_START_CONFIG_expected} ];then
    echo "[  OK  ] 允许系统启动或关闭时自动管理数据库实例配置完成!"
else
    echo "[  falsed  ] 允许系统启动或关闭时自动管理数据库实例配置失败!"
	exit 1
fi

#set oracle to use dbstart & dbshut to control the dbsoftware

#sed -i "s/ORACLE_HOME_LISTNER=\$1/ORACLE_HOME_LISTNER=\$ORACLE_HOME/g" ${DB_SHUT}
#sed -i "s/ORACLE_HOME_LISTNER=\$1/ORACLE_HOME_LISTNER=\$ORACLE_HOME/g" ${DB_START}
egrep -q "^ORACLE_HOME_LISTNER\s*.+(\s*#.*)?\s*$" ${DB_START} && sed -ri "s|^ORACLE_HOME_LISTNER\s*.+(\s*#.*)?\s*$|ORACLE_HOME_LISTNER=$ORACLE_HOME|" ${DB_START} && echo "[  OK  ] ${DB_START}配置ORACLE_HOME_LISTNER完成"|| (echo "ORACLE_HOME_LISTNER no in ${DB_START},please check";echo "[  faild  ] ${DB_START}配置ORACLE_HOME_LISTNER失败";exit 1)
egrep -q "^ORACLE_HOME_LISTNER\s*.+(\s*#.*)?\s*$" ${DB_SHUT} && sed -ri "s|^ORACLE_HOME_LISTNER\s*.+(\s*#.*)?\s*$|ORACLE_HOME_LISTNER=$ORACLE_HOME|" ${DB_SHUT} && echo "[  OK  ] ${DB_SHUT}配置ORACLE_HOME_LISTNER完成"|| (echo "ORACLE_HOME_LISTNER no in ${DB_SHUT},please check";echo "[  faild  ] ${DB_SHUT}配置ORACLE_HOME_LISTNER失败";exit 1)


#set oracle start&stop sys_service
echo "############################   Oracle sys_service  #######################################"
su - oracle -c "touch /home/oracle/oracle":
cat >/etc/init.d/oracle <<EOF
#!/bin/sh
# chkconfig: 35 80 10
# description: Oracle auto start-stop script.
# Set ORACLE_HOME to be equivalent to the \$ORACLE_HOME
# Oracle database in ORACLE_HOME.
LOGFILE=/home/oracle/oracle
ORACLE_HOME=$ORACLE_HOME
ORACLE_OWNER=oracle
LOCK_FILE=/var/lock/subsys/oracle
if [ ! -f $ORACLE_HOME/bin/dbstart ]
then
    echo "Oracle startup: cannot start"
    exit
fi
case "\$1" in
'start')
# Start the Oracle databases:
echo "Starting Oracle Databases ... "
echo "-------------------------------------------------" >> \${LOGFILE}
date +" %T %a %D : Starting Oracle Databases as part of system up." >> \${LOGFILE}
echo "-------------------------------------------------" >> \${LOGFILE}
su - \$ORACLE_OWNER -c "\$ORACLE_HOME/bin/dbstart" >> \${LOGFILE}
echo "Done"

# Start the Listener:
echo "Starting Oracle Listeners ... "
echo "-------------------------------------------------" >> \${LOGFILE}
date +" %T %a %D : Starting Oracle Listeners as part of system up." >> \${LOGFILE}
echo "-------------------------------------------------" >> \${LOGFILE}
su - \$ORACLE_OWNER -c "\$ORACLE_HOME/bin/lsnrctl start" >> \${LOGFILE}
echo "Done."
echo "-------------------------------------------------" >> \${LOGFILE}
date +" %T %a %D : Finished." >> \${LOGFILE}
echo "-------------------------------------------------" >> \${LOGFILE}
touch \$LOCK_FILE
;;

'stop')
# Stop the Oracle Listener:
echo "Stoping Oracle Listeners ... "
echo "-------------------------------------------------" >> \${LOGFILE}
date +" %T %a %D : Stoping Oracle Listener as part of system down." >> \${LOGFILE}
echo "-------------------------------------------------" >> \${LOGFILE}
su - \$ORACLE_OWNER -c "\$ORACLE_HOME/bin/lsnrctl stop" >> \${LOGFILE}
echo "Done."
rm -f \$LOCK_FILE

# Stop the Oracle Database:
echo "Stoping Oracle Databases ... "
echo "-------------------------------------------------" >> \${LOGFILE}
date +" %T %a %D : Stoping Oracle Databases as part of system down." >> \${LOGFILE}
echo "-------------------------------------------------" >> \${LOGFILE}
su - \$ORACLE_OWNER -c "\$ORACLE_HOME/bin/dbshut" >> \${LOGFILE}
echo "Done."
echo ""
echo "-------------------------------------------------" >> \${LOGFILE}
date +" %T %a %D : Finished." >> \${LOGFILE}
echo "-------------------------------------------------" >> \${LOGFILE}
;;

'restart')
\$0 stop
\$0 start
;;
esac
EOF
#set privileges
chmod +x /etc/init.d/oracle
chkconfig oracle on
# check oracle service
service oracle start
if [ $? -ne 0 ];then
  action "oracle service start failed." /bin/false
  exit 2
fi

service oracle stop
if [ $? -ne 0 ];then
  action "oracle service stop failed." /bin/false
  exit 3
fi

service oracle restart
if [ $? -ne 0 ];then
  action "oracle service restart failed." /bin/false
  exit 4
fi

#set create app_user && app_passwd && tablespace && grant
echo "############################   Oracle sys_service  #######################################"
su - oracle -c "${CDB_SQL}"
if [ $? -eq 0 ];then
  #echo -e "\e[30 CDB_SQL execute successed & restart the oracle_service \e[0m"
  echo "[  OK  ] CDB_SQL execute successed & restart the oracle_service"
  service oracle restart
else
  #action "oracle create app_user && app_passwd failed." /bin/false
  echo "[  FAILED  ] create app_user && app_passwd && tablespace && grant failed."
  exit 5
fi

echo "####################### oracle listener && dbca  安装完成 请记录数据库信息      ##############################"

echo "#####   oracle用户系统登录密码:      #####"
echo -e "\e[1;38;5;208m Oracle用户系统登录密码: $ORACLE_OS_PWD \e[0m"

echo "#####   数据库实例名:      #####"
echo -e "\e[1;38;5;208m 数据库实例名: $ORACLE_SID \e[0m"

echo "#####   数据库install.db.starterdb密码:      #####"
echo -e "\e[1;38;5;208m 数据库install.db.starterdb密码: $installSysPassword \e[0m"

echo "#####   数据库实例的sys管理用户密码:      #####"
echo -e "\e[1;38;5;208m 数据库实例的sys管理用户密码: $SYSPASSWORD \e[0m"

echo "#####   数据库应用连接用户名:      #####"
echo -e "\e[1;38;5;208m 数据库应用连接用户名: $USER_NAME \e[0m"

echo "#####   数据库应用连接用户名对应的密码:      #####"
echo -e "\e[1;38;5;208m 数据库应用连接用户名对应的密码: $USER_PASSWD \e[0m"

echo "#####   数据库临时表空间名:      #####"
echo -e "\e[1;38;5;208m 数据库临时表空间名: $TMP_DBF \e[0m"

echo "#####   数据库数据表空间名:      #####"
echo -e "\e[1;38;5;208m 数据库数据表空间名: $DATA_DBF \e[0m"


标签:shell,file,0.1,db,echo,install,oracle,response,oracle12.2
From: https://www.cnblogs.com/haiyoyo/p/18668244

相关文章

  • Powershell-2学习笔记
    声明!学习视频来自B站up主**泷羽sec**有兴趣的师傅可以关注一下,如涉及侵权马上删除文章,笔记只是方便各位师傅的学习和探讨,文章所提到的网站以及内容,只做学习交流,其他均与本人以及泷羽sec团队无关,切勿触碰法律底线,否则后果自负!!!!有兴趣的小伙伴可以点击下面连接进入b站主页[B站......
  • Xshell 远程连接软件
    哈喽啊亲们!今天也是快乐牛马的一天,小橘已经连续加班两天了,深刻体会到了这年头牛马的含义。言归正传,今天跟大家聊聊Xshell这个工具吧。xshell远程连接必备信息IP地址 端口号 用户名 密码 IP地址●IP地址是服务器的身份证号,在局域网内唯一;●公网IP:公网又......
  • 0.1 + 0.2、0.1 + 0.3和0.1 * 0.2分别等于多少?并解释下为什么?
    首先,我们直接计算这三个表达式的结果:0.1+0.2在JavaScript(一个常见的前端开发语言)中,这个表达式的结果是0.30000000000000004,而不是你可能期望的0.3。这是因为JavaScript使用64位浮点数表示数字,这导致某些十进制小数无法精确表示。当你尝试对这些不精确的数字进行算术运算时......
  • Windows10中安装了ubuntu虚拟机后xshell无法连接到ubuntu
    Windows10中安装了ubuntu虚拟机后xshell无法连接到ubuntu安装了ubuntu虚拟机后发现shell无法连接到ubuntu的排查步骤:步骤1:检查虚拟机网络配置确认虚拟机网络模式:确认虚拟机的网络模式是否设置为桥接模式或NAT模式。桥接模式可以让你的虚拟机在网络中拥有独立的IP地址,而NAT模式......
  • 在shell脚本中为日志添加颜色
    转自:https://www.cnblogs.com/ydswin/p/18667096在Shell脚本中,可以通过添加ANSI转义序列来为日志输出添加颜色。以下是一个完整的Shell脚本示例,包含日志颜色定义、日志函数封装以及使用示例:完整脚本:colored_logs.sh#!/bin/bash#定义颜色变量RED='\033[0;31m'GREEN='......
  • 在shell脚本中为日志添加颜色
    在Shell脚本中,可以通过添加ANSI转义序列来为日志输出添加颜色。以下是一个完整的Shell脚本示例,包含日志颜色定义、日志函数封装以及使用示例:完整脚本:colored_logs.sh#!/bin/bash#定义颜色变量RED='\033[0;31m'GREEN='\033[0;32m'YELLOW='\033[0;33m'BLUE='\033[0;3......
  • 泷羽Sec-Powershell2
    学习视频来自B站up主**泷羽sec**有兴趣的师傅可以关注一下,如涉及侵权马上删除文章,笔记只是方便各位师傅的学习和探讨,文章所提到的网站以及内容,只做学习交流,其他均与本人以及泷羽sec团队无关,切勿触碰法律底线,否则后果自负!!!有兴趣的小伙伴可以点击下面连接进入b站主页[B站泷......
  • shell脚本检查192.168.1网段ip是否在用
    要检查192.168.1网段中哪些IP地址正在使用,可以使用Shell脚本结合ping命令来扫描整个网段。以下是实现这一功能的完整脚本:脚本:检查192.168.1网段IP是否在用#!/bin/bash#定义网段NETWORK="192.168.1"#定义超时时间(秒)TIMEOUT=1#定义并行扫描的IP数量PAR......
  • Shelly聊AI:年度展望:2025年AI与社会发展关键事件的深度思考(每年一篇,十年为期)
    大家好,我是Shelly,一个专注于输出AI工具和科技前沿内容的AI应用教练,体验过300+款以上的AI应用工具。关注科技及大模型领域对社会的影响10年+。关注我一起驾驭AI工具,拥抱AI时代的到来。人工智能&AIGC术语100条Shelly聊AI-重磅发布在人类浩瀚的历史中,人工智能犹如一颗璀璨夺目......
  • Shell编程详解
    文章目录一、Linux系统结构二、Shell介绍1、Shell简介2、Shell种类3、Shell查询和切换三、Shell基础语法1、注释2、本地变量3、环境变量3.1、查看环境变量3.2、临时设置环境变量3.3、永久设置环境变量4、特殊变量5、控制语句5.1、shell中的中括号5.2、if语句5.3、for循......