Skip to content

Instantly share code, notes, and snippets.

@Zibri
Created August 5, 2019 17:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Zibri/387f0bd0acf09f71384ce78dd45aa058 to your computer and use it in GitHub Desktop.
Save Zibri/387f0bd0acf09f71384ce78dd45aa058 to your computer and use it in GitHub Desktop.
Get network data usage from Android phone.
#!/bin/bash
# Get android network usage statistics from phone.
# by Zibri
function getUsage ()
{
rb=0;
tb=0;
for a in $(adb shell dumpsys netstats|grep "rb="|cut -d "=" -f 3|cut -d " " -f 1);
do
rb=$((rb+a/1024));
done;
rb=$((rb/2));
for a in $(adb shell dumpsys netstats|grep "rb="|cut -d "=" -f 5|cut -d " " -f 1);
do
tb=$((tb+a/1024));
done;
tb=$((tb/2));
echo RX: $rb Kb TX: $tb Kb
echo Total: $(((rb+tb)/1024)) Mb
};
getUsage
@Zibri
Copy link
Author

Zibri commented Aug 5, 2019

$ ./getusage.sh
RX: 34189714 Kb TX: 872715 Kb
Total: 34240 Mb

@minoskt
Copy link

minoskt commented Jun 29, 2023

Thanks. May I ask why you are dividing by 2 in L17?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment