Practice: shell script for creating a tablespace in oracle

Source: Internet
Author: User

Practice: shell script for creating a tablespace in oracle

 

#! /Bin/bash # ocpyang@126.com # create tablespaceif [$ #-ne 2]; then echo "Usage: $0 TABLESPACE_NAME TABLESPACE_SIZE" exit 1fi # configure oracle env: about oracle envs, username and passwordORACLE_HOME =/u01/app/oracle/product/11.2.0/db_1ORACLE_SID = orclora_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 outfil Etmp01 =/tmp/createtpstmp01.txt # specify the output file location outfiletmp03 =/tmp/queues # 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 the execution result echo of sqlplus; set feedback off; set termout off; set pagesize 0; set verify off; set echo off; spool $ {outfiletmp01} select sysdate from dual; spool offexit ;! 01ins_jug = 'grep-I "ORA-01034:" ${outfiletmp01 }>$ {outfiletmp02} 'if [-s $ {outfiletmp02}]; thenecho-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 1fi # sqlplus-S "$ {ora_user}/$ {ora_pass} as sysdba" <! 01>/dev/null # disable the execution result echo of sqlplus; set feedback off; set termout off; set pagesize 0; set verify off; set echo off; spool $ outfiletmp03select tablespace_name from dba_tablespaces where tablespace_name = '$ {tablespace_name}'; spool offexit ;! 01tps_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 elsewind_var =$ (sqlplus-s" {ora_user}/$ {ora_pass} as sysdba "<EOF create tablespace $ {tablespace_name} datafile '$ {ora_data}/$ {tablespace_name }. dbf 'size $ tablespace_sizeextent management localuniform size 128 ksegment space management auto; EXIT; EOF) echo-e "\ e [1; 32 m $ {wind_var} \ e [0 m "# Direct display returns resultsrm-rf $ {outfiletmp03} exit 1fi


 

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.