Practice: Create shell scripts and oracleshell scripts for oracle users
#! /Bin/bash # ocpyang@126.com # create userif [$ #-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 1fi # configure oracle env: about ora Cle 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" 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 = $ 1chk_user = $ (echo $1 | tr '[a-z] ''[A-Z]') cre_user_pwd = $ 2def_tbsp = $ 3def_idx_tbsp = $ 4def_temp_tbsp = tempsmk_test_table = t1sqlplus-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 username from dba_users where username = '$ {chk_user}'; spool offexit ;! 01 # check oracle instance is down or up ins_jug = 'grep-I "ORA-01034:" ${outfiletmp01 }>$ {outfiletmp03} 'if [-s $ {outfiletmp03}]; 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 "exit 0fitps_jug = 'grep- I $ {chk_user }$ {outfiletmp01} 'if ["$ {tps_jug}" = "$ {chk_user}"]; thenecho-e "\ e [1; 31 m sorry, The username $ {cre_user} exits! \ E [0 m "exit 0elsewind_crtusr =$ (sqlplus-S" $ {ora_user}/$ {ora_pass} as sysdba "<! 01>/dev/null # disable sqlplus execution result echo 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 offexit ;! 01) # execute the variable $ wind_crtusrif ["$ {wind_crtusr}" = ""]; thenecho-e "\ e [1; 32 m OK, the create user $ {cre_user} success! \ E [0 m "elseecho-e" \ e [1; 31 m $ {wind_crtusr} \ e [0 m "firm-rf $ {outfiletmp01} rm-rf $ {outfiletmp02} rm-rf $ {outfiletmp03} exit 1fi
Linux + oracle database + shell scripts have been learned. What will happen in the future?
If you just want to learn, I believe there is nothing to show off, because linux + oracle + shell, basically I will. We recommend that you be proficient in one or two products. I believe this will allow you to develop your business in the future.
Linux + oralce is a lot of operating systems and databases used by many large enterprises. you are proficient in these two fields, and you have no problem with the monthly salary. GG or MM
How to write an oracle script to create a user
Start-run-cmd open the command prompt
Sqlplus "/as sysdba"
Create user username identified by passwd; -- create a username user. The password is passwd.
Grant session, resource to username; --- grant permissions to username to connect to and use database resources
Thank you for choosing