nicsensor/test_plugin/check_threhold.sh

45 lines
1.1 KiB
Bash
Raw Permalink Normal View History

#!/bin/sh
# 20250627
# A tool script to test a value greater or less than threhold
data=$1
direction=$2
threhold=$3
param_num=$#
print_usage(){
echo " Script Usage"
echo " ./check_threhold.sh <value> <direction> <threhold>"
echo " @Param direction : greater , >"
echo " less , <"
echo " equal , ="
echo ""
echo " E.G. ./check_threhold.sh 500 > 1000"
echo " +--> Result : 0"
echo ""
echo " About Result: 1 means true, 0 means fault"
echo ""
}
main(){
if [ ${param_num} -ne 3 ];then
print_usage
exit 0
fi
if [ "${direction}" = "great" ] || [ "${direction}" = ">" ];then
res= `echo " $data > $threhold" | bc -l`
elif [ "${direction}" = "less" ] || [ "${direction}" = "<" ];then
res= `echo " $data < $threhold" | bc -l`
elif [ "${direction}" = "equal" ] || [ "${direction}" = "=" ];then
res= `echo " $data = $threhold" | bc -l`
else
echo "Invalid direction"
print_usage
fi
echo $res
}
main