sql server 语句检测替换

#!/bin/bash
#检测是什么语句
#检测条件前面是否有;
#替换语句为select,进行查询备份
user=
pass=
host=
db=$1
port=1433
i=1
>/tmp/sql_resu.txt
[ $# -ne 2 ] && echo “Usage: `basename $0` dbname sqltxt” && exit
while read line
do
sql_type=`echo $line | awk ‘{print $1}’`
[ -z “$sql_type” ] && exit && echo “error…… 1 ”

if [[ “$sql_type” = “UPDATE” || “$sql_type” = “UPDATE” ]];then
table=`echo $line | awk ‘{print $2}’`
resu=`echo $line | sed -r ‘s#(.*)(where)(.*)#\1#i’ | grep “;”`
[ $? -ne 1 ] && echo “error, sql have ; …. please check…” && exit
rep_sql=`echo $line | sed -r “s#(.*)(where)(.*)#select * from $table \2 \3#i”`
echo $rep_sql >> /tmp/sql_resu.txt
# /opt/mssql-tools/bin/sqlcmd -U $user -P${pass} -S ${host},${port} -d ${db} -W -Q ‘”${rep_sql}”‘

fi

if [[ “$sql_type” = “DELETE” || “$sql_type” = “delete” ]];then
# table=`echo $line | sed -r ‘s#.*from (.*) where#\1#i’`

table=`echo $line | awk ‘{print $3}’`
resu=`echo $line | sed -r ‘s#(.*)(where)(.*)#\1\2#i’ | grep “where”`
[ $? -ne 0 ] && echo “error, sql have ; …. please check…” && exit
rep_sql=`echo $line | sed -r “s#(.*)(where)(.*)#select * from $table \2 \3#”`
echo $rep_sql >> /tmp/sql_resu.txt sqlcmd -U $user -P${pass} -S ${host},${port} -d ${db} -W -Q “${rep_sql}”
#/opt/mssql-tools/bin/sqlcmd -U $user -P${pass} -S ${host},${port} -d ${db} -W -Q “${rep_sql}”
echo “1”
fi

let i++
done < delete.txt
echo ” $i sql is finish….”
/opt/mssql-tools/bin/sqlcmd -U $user -P${pass} -S ${host},${port} -d ${db} -W –

暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇