summaryrefslogtreecommitdiff
path: root/dwmbar/bar_net_activity.sh
blob: f08fb4f6233c1763dc75b83c1e4047c0eeea1f21 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

# network activity

[ ! -f /tmp/netactup ] || touch /tmp/netactup
[ ! -f /tmp/netactdown ] || touch /tmp/netactdown 

# get previous results
rx_prev=$(cat /tmp/netactdown)
tx_prev=$(cat /tmp/netactup)

# convert results to integers
rx_prev=$(($rx_prev))
tx_prev=$(($tx_prev))

# set variables to sys files
rx_now=$(cat /sys/class/net/enp60s0/statistics/rx_bytes)
tx_now=$(cat /sys/class/net/enp60s0/statistics/tx_bytes)

# convert variables to integers
rx_now=$(($rx_now))
tx_now=$(($tx_now))

# caculate amount send and recieved
down_total=$((rx_now - rx_prev))
up_total=$((tx_now - tx_prev))

echo $rx_now > /tmp/netactdown
echo $tx_now > /tmp/netactup

echo "D:" $(numfmt --to=iec $down_total) "U:" $(numfmt --to=iec $up_total)