Can this be simplified?!
begin=$( date -d "-3 days" +%s )
total=$( vnstat -i eth0 --json | jq -r ".interfaces[0].traffic.fiveminute" | jq -r ".[] | select( .timestamp >= $begin ) | {"t": [.rx, .tx] | add}" | jq -r '[.t] | add' |
paste -sd+ | bc )
I feel that it ought to be possible in one jq
rather than three.
Similarly, it is implied that jq
should be able to do the sum by using |add
but that seems to be a lie.