首页 / 数据库 / MySQL / Oracle删除表空间的shell脚本实例
Oracle删除表空间的shell脚本代码#!/bin/bash
#ocpyang@126.com
#drop tablespaceif [ $# -ne 1 ]; then
echo "Usage: $0 TABLESPACE_NAME "
exit 1
fi#configure oracle env:about oracle envs, username and passwordORACLE_SID=orclORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1ora_data=/u01/app/oracle/product/11.2.0/db_1/dbs/
ora_user="sys" #oracle usernameora_pass="password" #oracle user passwordtablespace_name=$(echo $1 | tr "[a-z]" "[A-Z]")outfiletmp=/tmp/droptpstmp01.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
wind_var=$(
sqlplus -s "{ora_user}/${ora_pass} as sysdba" <<EOF
set heading off
drop tablespace ${tablespace_name} including contents and datafiles;
EXIT;
EOF)
echo -e "e[1;32m ${wind_var} e[0m" #Direct display returns results
rm -rf ${outfiletmp}
exit 1
else
echo -e "e[1;31m --------------------------------------- e[0m"
echo -e "e[1;31m The tablespace ${tablespace_name} not exits! e[0m"
echo -e "e[1;31m --------------------------------------- e[0m"
rm -rf ${outfiletmp}
exit 1fiOracle 11g 在RedHat Linux 5.8_x64平台的安装手册 http://www.linuxidc.com/Linux/2014-07/104745.htmLinux-6-64下安装Oracle 12C笔记 http://www.linuxidc.com/Linux/2013-07/86805.htm在CentOS 6.4下安装Oracle 11gR2(x64) http://www.linuxidc.com/Linux/2014-02/97374.htmOracle 11gR2 在VMWare虚拟机中安装步骤 http://www.linuxidc.com/Linux/2013-09/89579p2.htmDebian 下 安装 Oracle 11g XE R2 http://www.linuxidc.com/Linux/2014-03/98881.htm更多Oracle相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12本文永久更新链接地址