實戰:oracle 建立使用者shell指令碼,oracleshell

來源:互聯網
上載者:User

實戰:oracle 建立使用者shell指令碼,oracleshell

#!/bin/bash#ocpyang@126.com#create userif [ $# -ne 4 ]; then  echo -e "\e[1;32m  ********************************************************************************* \e[0m"   echo -e "\e[1;32m  Usage: $0 USERNAME PASSWORD DEFAULT_TABLESPACE INDEX_TABLESPACE \e[0m"  echo -e "\e[1;32m  ********************************************************************************* \e[0m"   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"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 #禁止sqlplus執行結果回顯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 offexit;!01##check oracle instance is down or up ins_jug=`grep -i "ORA-01034:"  ${outfiletmp01} >${outfiletmp03} ` if [  -s ${outfiletmp03} ]; thenecho -e "\e[1;31m  ******************************************************************  \e[0m"echo -e "\e[1;31m  !!!!, oracle IS down!  \e[0m"echo -e "\e[1;31m  ******************************************************************  \e[0m"exit 0fitps_jug=`grep -i ${chk_user} ${outfiletmp01} ` if [ "${tps_jug}" = "${chk_user}" ]; thenecho -e "\e[1;31m  sorry, The username ${cre_user} exits!  \e[0m"exit 0elsewind_crtusr=$(sqlplus -S "${ora_user}/${ora_pass} as sysdba" <<!01 >/dev/null #禁止sqlplus執行結果回顯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 testCONN ${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;32m  ok, The create user ${cre_user} success!  \e[0m"elseecho -e "\e[1;31m  ${wind_crtusr}   \e[0m"firm -rf ${outfiletmp01}rm -rf ${outfiletmp02}rm -rf ${outfiletmp03}exit 1fi
 
 


linux系統+oracle資料庫+shell指令碼都學會了,以後發展會怎?

如果只是學會,我相信沒什麼好炫耀的,因為linux+oracle+shell,基本的我都會。建議你精通一到兩個就可以了。其他略懂略懂,相信這樣的話,你就可以再未來的企業裡很好滴發展了。

linux+oralce是很多大型企業用的很多的作業系統和資料庫,精通了這兩門,你過萬月薪根本沒問題。加油吧GG或MM
 
怎編寫oracle指令碼建使用者

開始-運行-cmd 開啟命令提示字元
sqlplus "/as sysdba"
create user username identified by passwd; --建立username使用者,密碼是passwd
grant session,resource to username;---賦權,給username串連和使用資料庫資源的許可權

謝謝採納
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.