码迷,mamicode.com
首页 > 数据库 > 详细

实战:oracle新建表空间的shell脚本

时间:2014-09-25 16:08:07      阅读:210      评论:0      收藏:0      [点我收藏+]

标签:style   io   ar   for   sp   on   c   ad   ef   

#!/bin/bash
#ocpyang@126.com
#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
 
 
outfiletmp=/tmp/createtpstmp01.txt  #specify the output file location



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 $outfiletmp
select tablespace_name from dba_tablespaces where tablespace_name=‘${tablespace_name}‘;
spool off
exit;
!01

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

 

if [ "${tps_jug}" = "${tablespace_name}" ]; then   
    echo -e "\e[1;32m  The tablespace ${tablespace_name} exits! \e[0m"   
    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
 exit 1

fi


rm -rf ${outfiletmp}

 

 

 


 

 

实战:oracle新建表空间的shell脚本

标签:style   io   ar   for   sp   on   c   ad   ef   

原文地址:http://blog.csdn.net/yangzhawen/article/details/39550873

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!