自制oracle RAC 11g(oracle grid instructure)卸载脚本(linux环境下)

该脚本不设置删除用户,grid 软件家目录必须在“u01/app/”下才能删除该目录。

格式化asm磁盘,要求格式为:“/dev/*asm*”或者“/dev/raw/*raw?”。不是该格式只能手工格式化asm磁盘。

自11g开始官方推出自带删除程序。本脚本只是按照相应步骤编写的,不能替代其他版本grid软件,只针对grid 11g集群软件。只设置删除oracle grid instructure,不删除数据库。

#!/bin/bash
#the script deinstalls grid software
#last time:2019-02-05
#author: Eric wong
cd /etc/init.d &&
if [ -f ohasd ]||[ -f init.ohasd ];then
rm -f ohasd
rm -f init.ohasd
echo "ohasd,init.ohasd has deleted(1)"
else 
echo "no ohasd,init.ohasd exists.don't need to deal with(1)"
fi

#delete the file's name like ora*,inittab.crs
cd /etc/ &&
if [ -f inittab.crs ];then
rm -f inittab.crs
echo "inittab.crs has deleted(2)"
else
echo "no inittab.crs exists.don't need to deal with(2)"
fi
etcOra=$(ls -d /etc/ora* 2>/dev/null)
if [ -n "$etcOra" ];then
for i in 'ls ./ora*'
do 
rm -fr $i
echo "/etc/ora* files has deleted(3)"
done
else
echo "no /etc/ora* exists,don't need to deal with(3)"
fi

#check and kill the oralce processe
PID=$(ps -ef|grep -E 'ora_|d.bin |LOCAL=NO |asm_ |lsnr |crs |evm |css'|awk '{print $2}')
for pid in $PID
do
kill -9 $pid
echo "killed $pid(4)"
done

#delete the dir of "/tmp or var/tmp"
cd /tmp &&
tmpCVU=$(ls -d /tmp/CVU_* 2>/dev/null)
tmpOraInsta=$(ls -d /tmp/OraInsta* 2>/dev/null)
if [ -n "$tmpCVU" ]||[ -n "$tmpOraInsta" ];then
rm -rf CVU_*
rm -rf OraInsta*
echo "CVU_*,OraIsta* has deleted(5)"
else
echo "no CVU_*,OraIsta* exists,don't need to deal with(5)"
fi

if [ -f .oracle  ] ||[ -d "./.oracle" ];then
rm -rf .oracle
echo "/tmp/.oracle has deleted(6)"
else
echo "/tmp/ no .oracle exists don't need to deal with(6)"
fi

cd /var/tmp &&
if [ -f .oracle  ] ||[ -d "./.oracle" ];then
rm -rf .oracle
echo "/var/tmp/.oracle has deleted(7)"
else
echo "/var/tmp/ no .oracle exists,don't need to deal with(7)"
fi

#delete dir "/usr/local/bin/"
if [ -f /usr/local/bin/dbhome ]|| [ -f /usr/local/bin/oraenv ]|| [ -f /usr/local/bin/coraenv ];then
rm -rf /usr/local/bin/dbhome
rm -rf /usr/local/bin/oraenv
rm -rf /usr/local/bin/coraenv
echo "dbhome,oraenv,coraenv has deleted(8)"
else
echo "no dbhome,oraenv,coraenv exists,don't need to deal with(8)"
fi

#delete dir "/opt/ORCLfmap"
if [ -d /opt/ORCLfmap ];then
rm -fr /opt/ORCLfmap
echo "ORCLfmap has deleted(9)"
else
echo "no ORCLfmap exists,don't need to deal with(9)"
fi

#remove ORACLE_BASE
u01App=$(ls -d /u01/app/* 2>/dev/null)
if [ -n "$u01App" ];then
rm -fr /u01/app/*
echo "/u01/app/ dir has deleted(10)"
else
echo "no \"/u01/app/*\"exists,don't need to deal with (10)"
fi
#dd the ASM disk's name like *asm*
asmCount=$( ls /dev/*asm*  2>/dev/null|head -n 1|wc -m )
asmPathCount=$( ls /dev/*asm* 2>/dev/null|head -n 1)

#SIGN1
if [ ! -z $asmPathCount ];then
echo "your disk UDEV model"
num=$( ls /dev/*asm* 2>/dev/null |wc -l)
cd /dev
for (( d=1;d<=$num;d=d+1 ))
do
read -p "please input your ($d of $num) the end word of ASMdisk name(like\"b\",\"c\",\"d\"...):" endName
endNameCount=$( echo "$endName"|sed 's#(^\s*)|(\s*$)##g'|wc -m )
 if [ $endNameCount -gt 2 ];then
 echo "you entered too many words,formart failed ,please try again!"
 break
 fi

read -p "please input your ($d of $num) ASMdisk size(G):" diskSize 
isNumber=$(echo "$diskSize"|sed 's#^[0-9][0-9]*$##g')
echo $isNumber
 if [ -n "$isNumber" ];then
 echo "you entered words is not number type ,formart failed ,please try again!"
 break
 fi
echo "please wait..." &&
indisksize=$(( $diskSize*1024*1024 ))
echo "dd if=/dev/zero of=${asmPathCount:0:$(( $asmCount-2 ))}$endName bs=1024 count=$indisksize"|bash
echo "${asmPathCount:0:$(( $asmCount-2 ))}$endName ($d of $num) has formatted OK"
done
#SIGN1
fi


#dd the RAW disk's name like *raw?
rawCount=$( ls /dev/raw/*raw? 2>/dev/null|head -n 1|wc -m )
rawPathCount=$( ls /dev/raw/*raw? 2>/dev/null|head -n 1)

#SIGN2
if [ ! -z $rawPathCount ];then
echo "your disk RAW model"
num=$( ls /dev/raw/*raw? 2>/dev/null |wc -l)
cd /dev
for (( d=1;d<=$num;d=d+1 ))
do
read -p "please input your ($d of $num) the end word of RAWdisk name(like\"1\",\"2\",\"3\"...):" endName
endNameCount=$( echo "$endName"|sed 's#(^\s*)|(\s*$)##g'|wc -m )
 if [ $endNameCount -gt 2 ];then
 echo "you entered too many words,formart failed ,please try again!"
 break
 fi

read -p "please input your ($d of $num) RAWdisk size(G):" diskSize
isNumber=$(echo "$diskSize"|sed 's#^[0-9][0-9]*$##g')
 if [ -n "$isNumber" ];then
 echo "you entered words is not number type ,formart failed ,please try again!"
 break
 fi
echo "please wait..." &&
indisksize=$(( $diskSize*1024*1024 ))
echo "dd if=/dev/zero of=${rawPathCount:0:$(( $rawCount-2 ))}$endName bs=1024 count=$indisksize"|bash
echo "${rawPathCount:0:$(( $rawCount-2 ))}$endName ($d of $num) has formatted OK"
done

#SIGN2
else
echo "WARNNING! Detect that your disk does not meet the requirements of this script !Please format your disk manually!"
#SIGN2
fi
++a
发布了13 篇原创文章 · 获赞 0 · 访问量 1104

猜你喜欢

转载自blog.csdn.net/qq_40881607/article/details/86766000