英文:
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 "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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论