如何编写一个Shell脚本来进行数值比较?

huangapple go评论52阅读模式
英文:

How to write a shell script to compare values numerically?

问题

I want the file fig.txt read in a shell script like here the number is 8 so if the number/value is less and equal to the value 5000 it will alert via mail that lock file overflow and if not it will alert lock file is ok.

pkity:/tech/cmd/dump# cat lngtrans2.out

Lock table entries in use: 8 of 8000

Lock table high water mark: 12

Shared memory allocated: 1788 K (1 segments. The last segment was not locked in memory)

pkity:/tech/cmd/dump# grep "Lock table entries" lngtrans2.out | cut -d " " -f 14 > fig.txt

pkity:/tech/cmd/dump# cat fig.txt

8

pkity:/tech/cmd/dump#
英文:

I want the file fig.txt read in a shell script like here the number is 8 so if the number/value is less and equal to the value 5000 it will alert via mail that lock file overflow and if not it will alert lock file is ok.

pkity:/tech/cmd/dump# cat lngtrans2.out

Lock table entries in use:         8 of 8000

Lock table high water mark:        12

Shared memory allocated:           1788 K (1 segments. The last segment was not locked in memory)

pkity:/tech/cmd/dump#  grep "Lock table entries" lngtrans2.out | cut -d " " -f 14 > fig.txt

pkity:/tech/cmd/dump# cat fig.txt

8

pkity:/tech/cmd/dump#

答案1

得分: 1

你可以从类似以下的内容开始。

#!/bin/sh

locked=$(grep "Lock table entries" lngtrans2.out | cut -d " " -f 14)

if [ "${locked}" -le 5000 ]; then
    mail -s "Lock file overflow" someone@somewhere.com << EOF
Lock table entries in use critical: ${locked}
EOF
fi
英文:

You can start with something like this.

#!/bin/sh

locked=$(grep &quot;Lock table entries&quot; lngtrans2.out | cut -d &quot; &quot; -f 14)

if [ &quot;${locked}&quot; -le 5000 ]; then
	mail -s &quot;Lock file overflow&quot; someone@somewhere.com &lt;&lt; EOF
Lock table entries in use critical: ${locked}
EOF
fi

huangapple
  • 本文由 发表于 2023年2月6日 15:26:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/75358417.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定