7 replaced http://unix.stackexchange.com/ with https://unix.stackexchange.com/
source | link

By the look of things, your result variable has a . in it after the number making bash not recognise it as such. You can reproduce the error by simply doing:

[ 7. -gt 1 ]

If you add more of the script to your question, |I can suggest where this might be coming from.

Update

Looking at the full script, I would just replace the line:

result=$(echo "$used / $total * 100" |bc -l|cut -c -2)

With:

result=$(( 100 * used / total ))

Since used and total are integers and bash does integer arithmetic, though note the shifting of the multiplication be 100 to the beginning. Or if you want to ensure correct rounding ('integer division' in computing always effectively rounds down):

result=$( printf '%.0f' $(echo "$used / $total * 100" | bc -l) )

This will ensure that there are no trailing dots in result. The approach using cut is not a very good idea since it is only valid for result in the range 10-99. It will fail for a result from 0-9 (as in your case) and also numbers above 99.

Update 2

From @Stephane's comment below@Stephane's comment below, you are better to round down when comparing to thresholds. Considering this, there is another small error with the snippet in the question - notice the inconsistency between the comparisons used for the warn_level and the critical_level. The comparisons for warn_level are correct, but critical_level uses -le (lesser or equal) instead of -lt (just lesser). Consider when result is slightly larger than critical_level - it will be rounded down to critical_level and not trigger the critical warning even though it should (and would if a -lt comparison was used).

Perhaps not much of an issue, but here is the corrected code:

if [ "$result" -lt "$warn_level" ]; then
  echo "Memory OK. $result% used."
  exit 0;
elif [ "$result" -lt "$critical_level" ]; then
  echo "Memory WARNING. $result% used."
  exit 1;
else
  echo "Memory CRITICAL. $result% used."
  exit 2;
fi

The -ge tests are also redundant since these cases are implied on reaching the elif/else, so have been removed.

By the look of things, your result variable has a . in it after the number making bash not recognise it as such. You can reproduce the error by simply doing:

[ 7. -gt 1 ]

If you add more of the script to your question, |I can suggest where this might be coming from.

Update

Looking at the full script, I would just replace the line:

result=$(echo "$used / $total * 100" |bc -l|cut -c -2)

With:

result=$(( 100 * used / total ))

Since used and total are integers and bash does integer arithmetic, though note the shifting of the multiplication be 100 to the beginning. Or if you want to ensure correct rounding ('integer division' in computing always effectively rounds down):

result=$( printf '%.0f' $(echo "$used / $total * 100" | bc -l) )

This will ensure that there are no trailing dots in result. The approach using cut is not a very good idea since it is only valid for result in the range 10-99. It will fail for a result from 0-9 (as in your case) and also numbers above 99.

Update 2

From @Stephane's comment below, you are better to round down when comparing to thresholds. Considering this, there is another small error with the snippet in the question - notice the inconsistency between the comparisons used for the warn_level and the critical_level. The comparisons for warn_level are correct, but critical_level uses -le (lesser or equal) instead of -lt (just lesser). Consider when result is slightly larger than critical_level - it will be rounded down to critical_level and not trigger the critical warning even though it should (and would if a -lt comparison was used).

Perhaps not much of an issue, but here is the corrected code:

if [ "$result" -lt "$warn_level" ]; then
  echo "Memory OK. $result% used."
  exit 0;
elif [ "$result" -lt "$critical_level" ]; then
  echo "Memory WARNING. $result% used."
  exit 1;
else
  echo "Memory CRITICAL. $result% used."
  exit 2;
fi

The -ge tests are also redundant since these cases are implied on reaching the elif/else, so have been removed.

By the look of things, your result variable has a . in it after the number making bash not recognise it as such. You can reproduce the error by simply doing:

[ 7. -gt 1 ]

If you add more of the script to your question, |I can suggest where this might be coming from.

Update

Looking at the full script, I would just replace the line:

result=$(echo "$used / $total * 100" |bc -l|cut -c -2)

With:

result=$(( 100 * used / total ))

Since used and total are integers and bash does integer arithmetic, though note the shifting of the multiplication be 100 to the beginning. Or if you want to ensure correct rounding ('integer division' in computing always effectively rounds down):

result=$( printf '%.0f' $(echo "$used / $total * 100" | bc -l) )

This will ensure that there are no trailing dots in result. The approach using cut is not a very good idea since it is only valid for result in the range 10-99. It will fail for a result from 0-9 (as in your case) and also numbers above 99.

Update 2

From @Stephane's comment below, you are better to round down when comparing to thresholds. Considering this, there is another small error with the snippet in the question - notice the inconsistency between the comparisons used for the warn_level and the critical_level. The comparisons for warn_level are correct, but critical_level uses -le (lesser or equal) instead of -lt (just lesser). Consider when result is slightly larger than critical_level - it will be rounded down to critical_level and not trigger the critical warning even though it should (and would if a -lt comparison was used).

Perhaps not much of an issue, but here is the corrected code:

if [ "$result" -lt "$warn_level" ]; then
  echo "Memory OK. $result% used."
  exit 0;
elif [ "$result" -lt "$critical_level" ]; then
  echo "Memory WARNING. $result% used."
  exit 1;
else
  echo "Memory CRITICAL. $result% used."
  exit 2;
fi

The -ge tests are also redundant since these cases are implied on reaching the elif/else, so have been removed.

6 deleted 2 characters in body
source | link

By the look of things, your result variable has a . in it after the number making bash not recognise it as such. You can reproduce the error by simply doing:

[ 7. -gt 1 ]

If you add more of the script to your question, |I can suggest where this might be coming from.

Update

Looking at the full script, I would just replace the line:

result=$(echo "$used / $total * 100" |bc -l|cut -c -2)

With:

result=$(( 100 * $usedused / $totaltotal ))

Since used and total are integers and bash does integer arithmetic, though note the shifting of the multiplication be 100 to the beginning. Or if you want to ensure correct rounding ('integer division' in computing always effectively rounds down):

result=$( printf '%.0f' $(echo "$used / $total * 100" | bc -l) )

This will ensure that there are no trailing dots in result. The approach using cut is not a very good idea since it is only valid for result in the range 10-99. It will fail for a result from 0-9 (as in your case) and also numbers above 99.

Update 2

From @Stephane's comment below, you are better to round down when comparing to thresholds. Considering this, there is another small error with the snippet in the question - notice the inconsistency between the comparisons used for the warn_level and the critical_level. The comparisons for warn_level are correct, but critical_level uses -le (lesser or equal) instead of -lt (just lesser). Consider when result is slightly larger than critical_level - it will be rounded down to critical_level and not trigger the critical warning even though it should (and would if a -lt comparison was used).

Perhaps not much of an issue, but here is the corrected code:

if [ "$result" -lt "$warn_level" ]; then
  echo "Memory OK. $result% used."
  exit 0;
elif [ "$result" -lt "$critical_level" ]; then
  echo "Memory WARNING. $result% used."
  exit 1;
else
  echo "Memory CRITICAL. $result% used."
  exit 2;
fi

The -ge tests are also redundant since these cases are implied on reaching the elif/else, so have been removed.

By the look of things, your result variable has a . in it after the number making bash not recognise it as such. You can reproduce the error by simply doing:

[ 7. -gt 1 ]

If you add more of the script to your question, |I can suggest where this might be coming from.

Update

Looking at the full script, I would just replace the line:

result=$(echo "$used / $total * 100" |bc -l|cut -c -2)

With:

result=$(( 100 * $used / $total ))

Since used and total are integers and bash does integer arithmetic, though note the shifting of the multiplication be 100 to the beginning. Or if you want to ensure correct rounding ('integer division' in computing always effectively rounds down):

result=$( printf '%.0f' $(echo "$used / $total * 100" | bc -l) )

This will ensure that there are no trailing dots in result. The approach using cut is not a very good idea since it is only valid for result in the range 10-99. It will fail for a result from 0-9 (as in your case) and also numbers above 99.

Update 2

From @Stephane's comment below, you are better to round down when comparing to thresholds. Considering this, there is another small error with the snippet in the question - notice the inconsistency between the comparisons used for the warn_level and the critical_level. The comparisons for warn_level are correct, but critical_level uses -le (lesser or equal) instead of -lt (just lesser). Consider when result is slightly larger than critical_level - it will be rounded down to critical_level and not trigger the critical warning even though it should (and would if a -lt comparison was used).

Perhaps not much of an issue, but here is the corrected code:

if [ "$result" -lt "$warn_level" ]; then
  echo "Memory OK. $result% used."
  exit 0;
elif [ "$result" -lt "$critical_level" ]; then
  echo "Memory WARNING. $result% used."
  exit 1;
else
  echo "Memory CRITICAL. $result% used."
  exit 2;
fi

The -ge tests are also redundant since these cases are implied on reaching the elif/else, so have been removed.

By the look of things, your result variable has a . in it after the number making bash not recognise it as such. You can reproduce the error by simply doing:

[ 7. -gt 1 ]

If you add more of the script to your question, |I can suggest where this might be coming from.

Update

Looking at the full script, I would just replace the line:

result=$(echo "$used / $total * 100" |bc -l|cut -c -2)

With:

result=$(( 100 * used / total ))

Since used and total are integers and bash does integer arithmetic, though note the shifting of the multiplication be 100 to the beginning. Or if you want to ensure correct rounding ('integer division' in computing always effectively rounds down):

result=$( printf '%.0f' $(echo "$used / $total * 100" | bc -l) )

This will ensure that there are no trailing dots in result. The approach using cut is not a very good idea since it is only valid for result in the range 10-99. It will fail for a result from 0-9 (as in your case) and also numbers above 99.

Update 2

From @Stephane's comment below, you are better to round down when comparing to thresholds. Considering this, there is another small error with the snippet in the question - notice the inconsistency between the comparisons used for the warn_level and the critical_level. The comparisons for warn_level are correct, but critical_level uses -le (lesser or equal) instead of -lt (just lesser). Consider when result is slightly larger than critical_level - it will be rounded down to critical_level and not trigger the critical warning even though it should (and would if a -lt comparison was used).

Perhaps not much of an issue, but here is the corrected code:

if [ "$result" -lt "$warn_level" ]; then
  echo "Memory OK. $result% used."
  exit 0;
elif [ "$result" -lt "$critical_level" ]; then
  echo "Memory WARNING. $result% used."
  exit 1;
else
  echo "Memory CRITICAL. $result% used."
  exit 2;
fi

The -ge tests are also redundant since these cases are implied on reaching the elif/else, so have been removed.

5 added 1278 characters in body
source | link

By the look of things, your result variable has a . in it after the number making bash not recognise it as such. You can reproduce the error by simply doing:

[ 7. -gt 1 ]

If you add more of the script to your question, |I can suggest where this might be coming from.

Update

Looking at the full script, I would just replace the line:

result=$(echo "$used / $total * 100" |bc -l|cut -c -2)

With:

result=$(( 100 * $used / $total ))

Since used and total are integers and bash does integer arithmetic, though note the shifting of the multiplication be 100 to the beginning. Or if you want to ensure correct rounding ('integer division' in computing always effectively rounds down):

result=$( printf '%.0f' $(echo "$used / $total * 100" | bc -l) )

This will ensure that there are no trailing dots in result. The approach using cut is not a very good idea since it is only valid for result in the range 10-99. It will fail for a result from 0-9 (as in your case) and also numbers above 99.

Update 2

From @Stephane's comment below, you are better to round down when comparing to thresholds. Considering this, there is another small error with the snippet in the question - notice the inconsistency between the comparisons used for the warn_level and the critical_level. The comparisons for warn_level are correct, but critical_level uses -le (lesser or equal) instead of -lt (just lesser). Consider when result is slightly larger than critical_level - it will be rounded down to critical_level and not trigger the critical warning even though it should (and would if a -lt comparison was used).

Perhaps not much of an issue, but here is the corrected code:

if [ "$result" -lt "$warn_level" ]; then
  echo "Memory OK. $result% used."
  exit 0;
elif [ "$result" -lt "$critical_level" ]; then
  echo "Memory WARNING. $result% used."
  exit 1;
else
  echo "Memory CRITICAL. $result% used."
  exit 2;
fi

The -ge tests are also redundant since these cases are implied on reaching the elif/else, so have been removed.

By the look of things, your result variable has a . in it after the number making bash not recognise it as such. You can reproduce the error by simply doing:

[ 7. -gt 1 ]

If you add more of the script to your question, |I can suggest where this might be coming from.

Update

Looking at the full script, I would just replace the line:

result=$(echo "$used / $total * 100" |bc -l|cut -c -2)

With:

result=$(( 100 * $used / $total ))

Since used and total are integers and bash does integer arithmetic. Or if you want to ensure correct rounding ('integer division' in computing always effectively rounds down):

result=$( printf '%.0f' $(echo "$used / $total * 100" | bc -l) )

This will ensure that there are no trailing dots in result. The approach using cut is not a very good idea since it is only valid for result in the range 10-99. It will fail for a result from 0-9 (as in your case) and also numbers above 99.

By the look of things, your result variable has a . in it after the number making bash not recognise it as such. You can reproduce the error by simply doing:

[ 7. -gt 1 ]

If you add more of the script to your question, |I can suggest where this might be coming from.

Update

Looking at the full script, I would just replace the line:

result=$(echo "$used / $total * 100" |bc -l|cut -c -2)

With:

result=$(( 100 * $used / $total ))

Since used and total are integers and bash does integer arithmetic, though note the shifting of the multiplication be 100 to the beginning. Or if you want to ensure correct rounding ('integer division' in computing always effectively rounds down):

result=$( printf '%.0f' $(echo "$used / $total * 100" | bc -l) )

This will ensure that there are no trailing dots in result. The approach using cut is not a very good idea since it is only valid for result in the range 10-99. It will fail for a result from 0-9 (as in your case) and also numbers above 99.

Update 2

From @Stephane's comment below, you are better to round down when comparing to thresholds. Considering this, there is another small error with the snippet in the question - notice the inconsistency between the comparisons used for the warn_level and the critical_level. The comparisons for warn_level are correct, but critical_level uses -le (lesser or equal) instead of -lt (just lesser). Consider when result is slightly larger than critical_level - it will be rounded down to critical_level and not trigger the critical warning even though it should (and would if a -lt comparison was used).

Perhaps not much of an issue, but here is the corrected code:

if [ "$result" -lt "$warn_level" ]; then
  echo "Memory OK. $result% used."
  exit 0;
elif [ "$result" -lt "$critical_level" ]; then
  echo "Memory WARNING. $result% used."
  exit 1;
else
  echo "Memory CRITICAL. $result% used."
  exit 2;
fi

The -ge tests are also redundant since these cases are implied on reaching the elif/else, so have been removed.

4 added 5 characters in body
source | link
3 added 5 characters in body
source | link
2 added 267 characters in body
source | link
1
source | link