oracle杀用户建用户改密码脚本

Posted 雾火

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了oracle杀用户建用户改密码脚本相关的知识,希望对你有一定的参考价值。

# ********************************
# * dba_oracle_awr.sh
# ********************************
# Usage: dba_oracle_awr.sh -s [instance_name]
# -f [from time]
# -t [to time]
# -p [report type, html or text]
# -h [oracle home]
# -n [tns admin]
#
# time format: yyyymmddhh24miss.
# E.g 20110304170000 means 05:00:00pm, Mar 04, 2011
#
#
# **********************
# get parameters
# **********************
while getopts ":i:s:" opt
do
case $opt in
i) instance=$OPTARG
;;
s) schemaName=$OPTARG
;;
?) echo "$0: invalid option -$OPTARG">&2
exit 1
;;
esac
done

oracle_home=$ORACLE_HOME
if [ "$instance" = "" ]
then
echo "instance name(-i) needed"
echo "program exiting..."
exit 1
fi
if [ "$schemaName" = "" ]
then
echo "report_name name (-s} needed"
echo "program exiting..."
exit 1
fi

sqlplus="${oracle_home}/bin/sqlplus"
echo $sqlplus
echo "start imp dmp--------------------------------------------"

# *******************************
# get begin and end snapshot ID
# *******************************
lock_user()
{
echo "lock user: $schemaName ................"

sqlplus -S /nolog<<EOF
conn / as sysdba
set term off
ALTER USER $schemaName ACCOUNT LOCK;
EOF
}

restart_db()
{
echo "restart DB ................"

sqlplus -S /nolog<<EOF
conn / as sysdba
set term off
shutdown immediate;
startup;
EOF
}


create_kill_proc()
{
echo "create kill proc ................"
sqlplus -S /nolog<<EOF
conn / as sysdba
CREATE OR REPLACE PROCEDURE DBA_KILL_SCHEMANAME_SESSION(SCHEMA_NAME VARCHAR2) AS
s VARCHAR2(1000);
BEGIN
FOR CUR IN (select s.SID, s.SERIAL#
from v\$session s
where username = SCHEMA_NAME) LOOP
dbms_output.put_line(ALTER SYSTEM KILL SESSION ‘‘‘ || CUR.SID || , || CUR.SERIAL# || ‘‘‘‘);
s := ALTER SYSTEM KILL SESSION ‘‘‘ || CUR.SID || , || CUR.SERIAL# || ‘‘‘‘;
EXECUTE IMMEDIATE S;
END LOOP;
END;
/
EOF
}

exec_kill_proc()
{
echo "kill session ................"

sqlplus -S /nolog<<EOF
conn / as sysdba
exec DBA_KILL_SCHEMANAME_SESSION($schemaName);
EOF
}


lock_user()
{
echo "lock user ................"

sqlplus -S /nolog<<EOF
conn / as sysdba
ALTER USER $schemaName ACCOUNT LOCK;
EOF
}

unlock_user()
{
echo "unlock user ................"

sqlplus -S /nolog<<EOF
conn / as sysdba
ALTER USER $schemaName ACCOUNT UNLOCK;
EOF
}


del_user()
{
echo "drop user: $schemaName ................"

sqlplus -S /nolog<<EOF
conn / as sysdba
set term off
DROP USER $schemaName CASCADE;
EOF
}
# *******************************
# generate AWR report
# *******************************
create_user()
{
echo "create user: $schemaName ................"

sqlplus -S /nolog<<EOF
conn / as sysdba
set term off
CREATE USER $schemaName
IDENTIFIED BY VALUES $schemaName
DEFAULT TABLESPACE TRADE
TEMPORARY TABLESPACE TEMP
PROFILE DEFAULT
ACCOUNT UNLOCK;
GRANT CONNECT TO $schemaName;
GRANT IMP_FULL_DATABASE TO $schemaName;
GRANT PLUSTRACE TO $schemaName;
GRANT RESOURCE TO $schemaName;
ALTER USER $schemaName DEFAULT ROLE ALL;
GRANT ADVISOR TO $schemaName;
GRANT UNLIMITED TABLESPACE TO $schemaName;
GRANT EXECUTE ON SYS.DBMS_FGA TO $schemaName;
GRANT READ, WRITE ON DIRECTORY SYS.MY_EXPDP_DUMP TO $schemaName;
EOF
}

# *******************************
# main routing
# *******************************
change_pwd()
{
echo "change passwd................"
sqlplus -S /nolog<<EOF
conn / as sysdba
set term off
alter user $schemaName identified by howbuy_qa_qwerVBNM;
EOF
}


#restart_db

lock_user
#create_kill_proc
exec_kill_proc
del_user
create_user
change_pwd

 

保存为imp.sh

调用

 ./imp.sh  -i ORCL -s ${toUser}_${dataBase}

(必须大写,因为数据库会话名称都是大写)

以上是关于oracle杀用户建用户改密码脚本的主要内容,如果未能解决你的问题,请参考以下文章

Oracle-常用数据库对象笔记(片段)

Oracle 11g改密码有效期

改密码 SQL> /@oracleserviceorcl as sysdba alter user sys identified by root123456; Not logged on

oracle创建数据库权限不足,怎么弄啊

为啥改linux改了密码却没有用

oracle 用户密码原则