DEV Community

loading...

Discussion on: Monitor network (data) usage in linux

Collapse
piyush1104 profile image
Piyush Bansal

Hey, I changed the script for mac os. Hope it helps someone.

netu() {
    # [net]work [u]sage: check network usage stats
    ADDRESS=$(ifconfig en0 | grep inet | grep -v inet6 | cut -d ' ' -f2)
    TRANSMITTED_BYTES=$(netstat -ib -I en0 | grep $ADDRESS | awk '{print $10}')
    TRANSMITTED=$(bc <<< "scale=2; $TRANSMITTED_BYTES/1000000")
    RECEIVED_BYTES=$(netstat -ib -I en0 | grep $ADDRESS | awk '{print $7}')
    RECEIVED=$(bc <<< "scale=2; $RECEIVED_BYTES/1000000")

    printf "%s MB\n" "$(tput bold)🔼 TRANSMITTED $(tput sgr0): $TRANSMITTED"
    printf "%s MB\n" "$(tput bold)🔽 RECEIVED    $(tput sgr0): $RECEIVED"
}
Enter fullscreen mode Exit fullscreen mode
Collapse
bhupesh profile image