Create a shell script instance in Oracle
Code for creating a shell script instance in Oracle:
#! /Bin/bash
# Ocpyang@126.com
# Create user
If [$ #-ne 4]; then
Echo-e "\ e [1; 32 m ************************************** **************************************** * ** \ e [0 m"
Echo-e "\ e [1; 32 m Usage: $0 username password DEFAULT_TABLESPACE INDEX_TABLESPACE \ e [0 m"
Echo-e "\ e [1; 32 m ************************************** **************************************** * ** \ e [0 m"
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"
Outfiletmp01 =/tmp/createusertmp01.txt # specify the output file location
Outfiletmp02 =/tmp/createusertmp02.txt # specify the output file location
Outfiletmp03 =/tmp/createusertmp03.txt # specify the output file location
Cre_user = $1
Chk_user = $ (echo $1 | tr '[a-z] ''[A-Z]')
Cre_user_pwd = $2
Def_tbsp = $3
Def_idx_tbsp = $4
Def_temp_tbsp = temp
Smk_test_table = t1
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 username from dba_users where username = '$ {chk_user }';
Spool off
Exit;
! 01
# Check whether oracle instance is down or up
Ins_jug = 'grep-I "ORA-01034:" ${outfiletmp01 }>$ {outfiletmp03 }'
If [-s $ {outfiletmp03}]; 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"
Exit 0
Fi
Tps_jug = 'grep-I $ {chk_user }$ {outfiletmp01 }'
If ["$ {tps_jug}" = "$ {chk_user}"]; then
Echo-e "\ e [1; 31 m sorry, The username $ {cre_user} exits! \ E [0 m"
Exit 0
Else
Wind_crtusr = $ (
Sqlplus-S "$ {ora_user}/$ {ora_pass} as sysdba" <! 01>/dev/null # disable display of sqlplus execution results
Spool $ {outfiletmp02}
Create user $ {cre_user} identified by $ {cre_user_pwd}
Default tablespace $ {def_tbsp}
Temporary tablespace $ {def_temp_tbsp };
Grant create session to $ {cre_user };
Grant create table to $ {cre_user };
Grant create index to $ {cre_user };
Alter user $ {cre_user} quota unlimited on $ {def_tbsp };
Alter user $ {cre_user} quota unlimited on $ {def_idx_tbsp };
-- Smoke test
CONN $ {cre_user}/$ {cre_user_pwd}
Create table $ {smk_test_table} (tid NUMBER) TABLESPACE $ {def_tbsp };
Create index $ {smk_test_table}. idx1 ON $ {cre_user}. $ {smk_test_table} (tid) TABLESPACE $ {def_idx_tbsp };
Insert into $ {smk_test_table} VALUES (1 );
Drop table $ {smk_ttbl };
Spool off
Exit;
! 01)
# Execute the variable $ wind_crtusr
If ["$ {wind_crtusr}" = ""]; then
Echo-e "\ e [1; 32 m OK, The create user $ {cre_user} success! \ E [0 m"
Else
Echo-e "\ e [1; 31 m $ {wind_crtusr} \ e [0 m"
Fi
Rm-rf $ {outfiletmp01}
Rm-rf $ {outfiletmp02}
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