用于检测db2死锁的脚本

时间:2013-11-28 12:05:04

标签: bash scripting db2

我正在尝试编写脚本,检查自上次运行脚本以来是否创建了新的死锁,如果自上次运行后没有新的死锁,如果创建了新的死锁则应该打印0然后它应该打印数字

     #DB profile
     . /db2/tdb_inst/archinst/sqllib/db2profile;
     #variable to get current deadlock count
     a=`db2 get snapshot for all on archprd |grep Deadlock|head -1|awk '{print $4}'`
     #variable to get last deadlock count
     b=`cat /home/dbmon/script/darch`

     #need your help to do below math in script
     #  if a$-b$ = 0  print 0 if a$-b$ > 0 print number 

     #after print export current deadlock count to darch file
     echo $a > /home/dbmon/script/darch

TIA tnt5273

1 个答案:

答案 0 :(得分:2)

  

需要你的帮助才能在脚本中进行数学运算

     

如果$ -b $ = 0打印0,如果$ -b $> 0打印编号

你可以说:

(( a - b )) && echo $(( a - b )) || echo 0

如果0打印a = b,则会打印a - b


实际上,即使是以下内容就足够了:

echo $(( a - b ))