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