shell脚本实现linux下自动安装Oracle10g

本文介绍的shell脚本是我初学shell脚本编程时为了练习shell编程,也为了方便oracle初装写的。大家都知道Oracle在linux下的安装是很繁琐 的,而且容易出错,也比较耗时。对于初学Oracle的新手来说,可能会遇到经常重装ORACLE的情况,如果把精力过多的用于安装,感觉会有点得不偿 失。
本脚本所做的事情并不是完全的安装好ORCLE,那也是不可能的事情,因为ORACLE安装的后期是有图形界面的交互模式,所以本脚本所做的只是前期环境配置,但就是这些前期配置才是最耗时的,所以写成脚本很必要。
本脚本只在RHEL5U3上做过测试,可以正常使用,对于其他版本有待验证和完善。

#!/bin/bash
#This program is used for helping you install oracle10g automatically.
#Be used in Redhat 5 enterprise.
#Statment:Before installing oracle10g by this program,you should prepare oracle10g tar.gz file, rlwrap and redhat install CD path.If you have any question about this program,you could contact me by the following email address.
#Author:Xinggang
#Written on xxxx

trap 'echo;exit 0;' 2 #Set trap,so you can interrupt the program when it is running.

shmmax=$(($(free |awk 'NR==2{print $2}')*1024/2)) #Set the argument "shmmax" according to the memory size of your computer.

read -p "Please input the oracle username that you want to create:" ooname
read -p "Please verify the oracle username:" oname

until [ ! -z "$oname" ] #Make judgment about if the variable $oname you given is null.
do
read -p "Please verify the oracle username:" oname
done

username=$(awk -F: '{print $1}' /etc/passwd)
for i in $username #Judge about if $oname already exists in your system.
do
if [ $oname = $i ]
then
echo "Error!The username you input is already exists in your system."; exit 1
fi
done

until [ ${oname}x = ${ooname}x ] #Make sure that the input is the very one which you want.
do
read -p "Please input the oracle username that you want to create:" ooname
read -p "Please verify the oracle username:" oname
if [ -z "$oname" ] #If $oname is still null,then exit this program.
then
echo "Error!"
exit 1
fi
done

read -p "Please input rlwrap path:" rlpath

read -p "Please input the path of CD:" cdpath
until [ -e "$cdpath"/Server ] #Make sure the path that you given is right.
do
read -p "Wrong path of CD,please retry:" cdpath
done

read -p "Please input your oracle tar.gz package name(include path) :" opackage

if [ ! -f "$opackage" ]
then
echo "The package is wrong!"
exit 1
fi

{
groupadd oinstall
groupadd dba
useradd -m -g oinstall -G dba $oname
mkdir -p /u01/app/$oname
chown -R $oname:oinstall /u01/app/$oname
chmod -R 775 /u01/app/$oname
}&>/dev/null

tar -zxf $opackage -C /home/$oname &>/dev/null

until [ "$?" -eq "0" ] #Make sure that the package you given is absolutely right.
do
read -p "Wrong package,please retry:" opachage
tar -zxf $opackage -C /home/$oname &>/dev/null
done

pushd $cdpath/Server &>/dev/null
{
rpm -Uvh compat-db-4*
rpm -Uvh libaio-0*
rpm -Uvh compat-libstdc++-33-3*
rpm -Uvh compat-gcc-34-3*
rpm -Uvh compat-gcc-34-c++-3*
rpm -Uvh libXp-1*
rpm -Uvh openmotif-2*
rpm -Uvh gcc-4*
}&>/dev/null
#rpm -Uvh glibc-2.5-12.i686.rpm
popd &>/dev/null

flag=0
{
pushd $rlpath
$rlpath/configure
make && make install
popd
}&>/dev/null

if [ "$?" -eq "1" ] #Be used for judging if rlwrap was compiled successfully.
then
flag=1
fi

grep 'fs.file-max' /etc/sysctl.conf &>/dev/null
if [ "$?" -eq "1" ] #Make jugdement if the configure file was already configured.
then

sed -i '/^kernel.shmmax/d' /etc/sysctl.conf #Delete the argument "kernerl.shmmax" in the configure file.
sed -i '/^kernel.shmall/d' /etc/sysctl.conf #Delete the argument "kernel.shmall" in the configure file

cat >> /etc/sysctl.conf <<EOF
kernel.shmall = 2097152
kernel.shmmax = $shmmax
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
fs.file-max = 65536
net.ipv4.ip_local_port_range = 1024 65000
net.core.rmem_default=262144
net.core.rmem_max=262144
net.core.wmem_default=262144
net.core.wmem_max=262144
#signaturelevin
EOF
fi

sysctl -p &>/dev/null #Make the configured file come into effect immediately.

grep 'soft nproc' /etc/security/limits.conf &>/dev/null
if [ "$?" -eq "1" ]
then
cat >> /etc/security/limits.conf <<EOF
soft nproc 2047
hard nproc 16384
soft nofile 1024
hard nofile 65536
#signaturelevin
EOF
fi

grep 'pam_limits.so' /etc/pam.d/login &>/dev/null
if [ "$?" -eq "1" ]
then
cat >> /etc/pam.d/login <<EOF
session required pam_limits.so
#signaturelevin
EOF
fi

grep 'ORACLE_SID=orcl' /home/$oname/.bash_profile &>/dev/null
if [ "$?" -eq "1" ]
then
cat >>/home/$oname/.bash_profile <<EOF
export TMP=/tmp
export ORACLE_BASE=/u01/app/$oname
export ORACLE_HOME=\$ORACLE_BASE/product/10g
export ORACLE_SID=orcl
export PATH=\$ORACLE_HOME/bin:\$PATH
export LD_LIBRARY_PATH=\$ORACLE_HOME/lib:/lib:/usr/lib
export CLASSPATH=\$ORACLE_HOME/JRE:\$ORACLE_HOME/jlib:\$ORACLE_HOME/rdbms/jlib
alias sqlplus="rlwrap sqlplus"
alias rman="rlwrap rman"
alias fox="firefox"
#signaturelevin
EOF
fi

. /home/$oname/.bash_profile

sed -i 's/5/4/' /etc/redhat-release #Resovling the problems brought by the version of your system.

xhost + &>/dev/null

echo -e "\a"
if [ "$flag" -eq "1" ]
then
echo -e "Configure successful but the rlwrap was not compiled successfully.You should compile it by your own after finishing installs of oracle10g.Now,the following steps are your own work.\n \n 1.export LANG=C \n 2.cd database/\n 3../runInstaller\n 4.Configure according to the Oracle GUI information.\n"
else
echo -e "Configure successful!The following steps are your own work.Just do it.\n \n 1.export LANG=C \n 2.cd database/\n 3../runInstaller\n 4.Configure according to the Oracle GUI information.\n"
fi

su - $oname


本文出自 “ 发现生命中的美丽” 博客,请务必保留此出处 http://findingcc.blog.51cto.com/1045158/233515

你可能感兴趣的:(oracle10g)