删除数据库用户

#!/usr/bin/ksh
#################################
# 1、upload the shell command to the server
# 2、grant the 777 to the command
# 3、use method like as follow: ./dropuser.sh username
# the username as the parameter for the shell command
# and the username is not distinguish the upper and lowwer
##################################
echo "start delete link"
userName=$1;
userName=`echo $userName |tr "[a-z]" "[A-Z]"`;
querysessionnum=`sqlplus / as sysdba << EOF
Select count(*) from v\\$session where username='$userName';
Select sid,SERIAL# from v\\$session where username='$userName';
EOF`

droplink=`sqlplus / as sysdba << EOF
drop user $userName cascade;
EOF`

sessionnum=`echo $querysessionnum | awk -F'SQL>' '{print $2}' | awk -F' ---------- ' '{print $2}'`

echo "link number :"$sessionnum
if [ $sessionnum = 0 ]
then
    temp=`echo $droplink`
    exit
fi    
sessionsidser=`echo $querysessionnum | awk -F'SQL>' '{print $3}'`
i=2
while true
do
    sessionsids=`echo $sessionsidser | awk -F'SID SERIAL# ---------- ----------' '{print $'$i';}' | awk -F'rows selected.' '{print $1}'`
    if [ "x$sessionsids" = "x" ]
    then
        break;
    fi
    numindex=1
    while true
    do
        sessionsidone=`echo $sessionsids | awk -F' ' '{print $'$numindex';}'`
        if [ "x$sessionsidone" = "x" ]
        then
            break;
        fi
        let numindex=numindex+1
        sessionsidtwo=`echo $sessionsids | awk -F' ' '{print $'$numindex';}'`
        if [ "x$sessionsidtwo" = "x" ]
        then
            break;
        fi
        let numindex=numindex+1
        echo "alter system kill session  '$sessionsidone,$sessionsidtwo';" >> dellik.sql
    done
    let i=i+1    
done
sqlplus / as sysdba << EOF
    @dellik.sql
EOF
rm dellik.sql

temp=`echo $droplink`


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值