I want to get my data usage from my wifi device to display on my top bar, I can get the data usage in bytes using curl like this
$bytes=(curl -d "Page=GetWANInfo" -X POST http://jiofi.local.html/cgi-bin/qcmap_web_cgi -s| jq -r .total_data_used)
it gives me a big number like 411982397
now I want to convert it in MBs and want to display it like 411.9 MB
but I am unable to figure out how can I format that big number like this.
I tried using bc
to convert it into MB echo $bytes / 1000000 | bc
but I am unable to put that into a variable it is giving me errors.
$ total=($bytes / 1000000 | bc)
bash: syntax error near unexpected token `|'
$ total=$($bytes / 1000000 | bc)
411982397: command not found
$ echo "$bytes / 1000000" | bc
411
$ total=$("$bytes / 1000000" | bc)
bash: 411982397 / 1000000: No such file or directory
my Idea here is to put that output in a variable than I can just echo $total MB
What can be a better approach for this problem? also I need to run this command every few seconds so I need a efficient solution to the problem which is easy to cpu