-
Notifications
You must be signed in to change notification settings - Fork 0
/
mod_network
executable file
·43 lines (32 loc) · 1.14 KB
/
mod_network
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
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env bash
. .dzenbarrc
MONITOR=${1}
PIPE_LINE=${2}
calculate() {
local sum=0
for arg; do
read -r i < "${arg}"
sum=$(( sum + i ))
done
cache="/tmp/cache_${1##*/}"
[[ -f "${cache}" ]] && read -r old < "${cache}" || old=0
echo "${sum}" > "${cache}"
echo $(( sum - old ))
}
# 1st call for cache
rxb=$(calculate /sys/class/net/[ew]*/statistics/rx_bytes)
txb=$(calculate /sys/class/net/[ew]*/statistics/tx_bytes)
while true; do
rxb=$(echo "$(calculate /sys/class/net/[ew]*/statistics/rx_bytes) / 1024 / ${NETWORK_UPDATE}" | bc -l | xargs printf "%.2f")
txb=$(echo "$(calculate /sys/class/net/[ew]*/statistics/tx_bytes) / 1024 / ${NETWORK_UPDATE}" | bc -l | xargs printf "%.2f")
# wireless check
wstatus="$(cat /sys/class/net/w*/operstate 2>/dev/null)"
if [[ "$wstatus" == "up" ]]; then
icon="$(iconColor 'wireless') $(awk '/^\s*w/ { print int($3 * 100 / 70) }' /proc/net/wireless)%"
else
icon="$(iconColor 'wired')"
fi
output=" ${icon} $(iconColor 'down' '#859900') $(textColor "${rxb}")kBs $(iconColor 'up' '#B58900') $(textColor "${txb}")kBs"
putLineToPipeFile ${MONITOR} ${PIPE_LINE} "${output}"
sleep ${NETWORK_UPDATE}
done