程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> Oracle數據庫 >> Oracle教程 >> 實戰:oracle新建表空間的shell腳本

實戰:oracle新建表空間的shell腳本

編輯:Oracle教程

實戰:oracle新建表空間的shell腳本


 

#!/bin/bash
#[email protected]
#create tablespace

if [ $# -ne 2 ]; then
  echo "Usage: $0 TABLESPACE_NAME TABLESPACE_SIZE"
  exit 1
fi

#configure oracle env:about oracle envs, username and password

ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1

ORACLE_SID=orcl

ora_data=/u01/app/oracle/product/11.2.0/db_1/dbs/


ora_user="sys"

ora_pass="password"


tablespace_name=$(echo $1 | tr '[a-z]' '[A-Z]') 

tablespace_size=$2
  
  
outfiletmp01=/tmp/createtpstmp01.txt  #specify the output file location 

outfiletmp03=/tmp/createtpstmp03.txt  #specify the output file location 

outfiletmp02=/tmp/createtpstmp02.txt  #specify the output file location 



#check oracle instance is down or up 

sqlplus -S "${ora_user}/${ora_pass} as sysdba" <<!01 >/dev/null #禁止sqlplus執行結果回顯
set heading off;
set feedback off;
set termout off;
set pagesize 0;
set verify off;
set echo off;
spool ${outfiletmp01}
select sysdate from dual; 
spool off
exit;
!01


ins_jug=`grep -i "ORA-01034:"  ${outfiletmp01} >${outfiletmp02} ` 
if [ -s ${outfiletmp02} ]; then
	echo -e "\e[1;31m  ******************************************************************  \e[0m"
	echo -e "\e[1;31m  !!!!, oracle IS down!  \e[0m"
	echo -e "\e[1;31m  ******************************************************************  \e[0m"
	rm -rf ${outfiletmp01}
	rm -rf ${outfiletmp02}
	exit 1

fi







#  
sqlplus -S "${ora_user}/${ora_pass} as sysdba" <<!01 >/dev/null #禁止sqlplus執行結果回顯
set heading off;
set feedback off;
set termout off;
set pagesize 0;
set verify off;
set echo off;
spool $outfiletmp03
select tablespace_name from dba_tablespaces where tablespace_name='${tablespace_name}'; 
spool off
exit;
!01

tps_jug=`grep -i ${tablespace_name} ${outfiletmp03} ` 



if [ "${tps_jug}" = "${tablespace_name}" ]; then    
    echo -e "\e[1;32m  The tablespace ${tablespace_name} exits! \e[0m"  
    rm -rf ${outfiletmp03}
    exit 1  
else
	wind_var=$(
	sqlplus -s "{ora_user}/${ora_pass} as sysdba" <<EOF 
	create tablespace ${tablespace_name}
	datafile '${ora_data}/${tablespace_name}.dbf'
	size $tablespace_size
	extent management local
	uniform size 128k
	segment space management auto;
	EXIT ;
	EOF) 
	echo -e "\e[1;32m  ${wind_var} \e[0m"   #Direct display returns results
	rm -rf ${outfiletmp03}
	exit 1

fi












 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved