-4

This recently stopped working. Any idea if I need to change anything in code?

TIME=`grep real < /tmp/EV_Check.time | cut -d ' ' -f2`
time=$TIME
test $time -ge $ct
result=$?
        if [ "$result" -eq "1" ]
        then
        crit=1
        msg="Report execution takes $time!"
        fi
test $time -ge $wt
result=$?
        if [ "$result" -eq "1" ]
        then
        warn=1
        msg="Report execution takes $time!"
        fi

if [ $crit -eq 1 -a $warn -eq 0 ]
then
       echo "Critical value must be greater than warning value !"
       help_usage
       exit 3
fi

I am getting the below error:-

./check_ev_report.sh: line 158: test: 0.45: integer expression expected
./check_ev_report.sh: line 166: test: 0.45: integer expression expected
OK - 0.45
  • 3
    Always quote your variables. Start there. – DopeGhoti Nov 22 '16 at 20:49
  • 1
    I suspect that your file /tmp/EV_Check.time contains the output of time. Bash arithmetic, including -ge, works on integers only. Decimal points are not allowed, much less strings like 9m50.017s. – AlexP Nov 22 '16 at 20:52
  • 2
    test and [ are the same command! – Stéphane Chazelas Nov 22 '16 at 21:23
  • 2
    That's not the script that produces that output. One giveaway is the OK. Another is that you have errors on lines 158 and 166 of a 23-line script. – JdeBP Nov 22 '16 at 22:29
  • It helps if you make a minimal reproducible example. As @JdeBP pointed out, it's obvious that you didn't do that. :) – Wildcard Nov 22 '16 at 22:52
3

bash can only do integer arithmetic.

If you want to compare floating point values, you'll have to call out to an external tool such as bc

if [[ $(bc <<<"$time >= $ct") == "1" ]]; then
    do_something
fi

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.