我正在尝试编写脚本,检查自上次运行脚本以来是否创建了新的死锁,如果自上次运行后没有新的死锁,如果创建了新的死锁则应该打印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
答案 0 :(得分:2)
需要你的帮助才能在脚本中进行数学运算
如果$ -b $ = 0打印0,如果$ -b $> 0打印编号
你可以说:
(( a - b )) && echo $(( a - b )) || echo 0
如果0
打印a = b
,则会打印a - b
。
实际上,即使是以下内容就足够了:
echo $(( a - b ))