Shell script instance for creating a tablespace in Oracle

Source: Internet
Author: User

Shell script instance for creating a tablespace in Oracle

Shell script instance code for creating a tablespace in Oracle:

#! /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


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 # disable display of sqlplus execution results
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; 31 m ************************************** * ************************** \ e [0 m"
Echo-e "\ e [1; 31 m !!!!, Oracle IS down! \ E [0 m"
Echo-e "\ e [1; 31 m ************************************** * ************************** \ e [0 m"
Rm-rf $ {outfiletmp01}
Rm-rf $ {outfiletmp02}
Exit 1

Fi

 

 

 

#
Sqlplus-S "$ {ora_user}/$ {ora_pass} as sysdba" <! 01>/dev/null # disable display of sqlplus execution results
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; 32 m The tablespace $ {tablespace_name} exits! \ E [0 m"
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 128 k
Segment space management auto;
EXIT;
EOF)
Echo-e "\ e [1; 32 m $ {wind_var} \ e [0 m" # Direct display returns results
Rm-rf $ {outfiletmp03}
Exit 1

Fi

Oracle 11g installation manual on RedHat Linux 5.8 _ x64 Platform

Installing Oracle 12C in Linux-6-64

Install Oracle 11gR2 (x64) in CentOS 6.4)

Steps for installing Oracle 11gR2 in vmwarevm

Install Oracle 11g XE R2 In Debian

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.