Domanda

I am creating a bash script to get the total number of transactions in a day, It'll include total, success and failed.

So far I could get those numbers, but I also need to create a successful average and failed average.

Now, let say that I got 1000 transactions which 900 were successful and 100 failed. For instance we can say that we have a success ratio of 90 % and a 10 % failure

When I try to do the maths I cannot get those percentages. I am saving the transactions number into variables so I have

"$TOTAL"=1000
"$SUCCESS"=900
"$FAILED"=100

I have tried the next codes failing in every attempt

AVERAGE=("$FAILED"*100)/"$TOTAL" | bc
AVERAGE=(\("$FAILED"*100)/"$TOTAL" | bc)
È stato utile?

Soluzione

You can do:

$ TOTAL=1000
$ SUCCESS=900
$ FAILED=100
$ AVERAGE=$((FAILED*100/TOTAL))
$ echo $AVERAGE
10
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top