Shell操作数据库流控脚本实例

#!/bin/bash

if [ "$(whoami)" != "root" ]; then
echo "Current username must be root!"
return 1
fi
sqlfile="./updatedetail.log"
m=$1
if [ -z "$m" ]; then
    m=2000
fi

tag=`. /home/oracle/.bash_profile; sqlplus -S dbo/passport@abc<<!
set head off
select max(id),min(id) from t_subscriber;
quit
!
`

count=`echo "${tag}"|awk '{print $1}'|xargs`
begin=`echo "${tag}"|awk '{print $2}'|xargs`



loop=$[($count-$begin+$m-1)/$m]
index=0


rm -rf $sqlfile
while [ "$index" -lt "$loop" ]; do
    ID1=$[$m*${index}+$begin]
    ID2=$[$m*(${index}+1)+$begin]
    let index=index+1
   
    cmd="UPDATE (SELECT SUBONLINESTATUS,CLUSTERPARTIONNAME FROM T_SUBSCRIBER WHERE CLUSTERPARTIONNAME IS NOT NULL AND ID>=${ID1} AND ID<=${ID2}) SET SUBONLINESTATUS = 2,CLUSTERPARTIONNAME=NULL;"
    echo "HOST echo 'NO. $index/$loop'">>$sqlfile
    echo "${cmd}" >>$sqlfile
   
    cmdline=". /home/oracle/.bash_profile
lmtruntime -500 sqlplus -S dbo/passport<<!
${cmd}
commit
quit
!"
    su - oracle -c "${cmdline}" > tmp.log
    result=`cat ./tmp.log`
        rm -f ./tmp.log
if [ "$(echo "${result}" | grep -c 'ORA-')" != "0" ]; then
"Update failed" >>$sqlfile
exit
else
  echo "COMMIT;" >>$sqlfile
fi 

    echo "HOST sleep $n" >>$sqlfile
done

echo "HOST echo 'Done!'" >>$sqlfile
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值