about summary refs log tree commit diff stats
path: root/home-manager/config/yambar/scripts/old/meminfo
blob: 0156e94c8a5683046f29aed03e57ab0b974c42d0 (plain) (blame)
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
#!/bin/sh
# Checks memory usage

# Number of seconds to retest
timer=5

# Main loop
while true; do

    mem_total=$(LANG=C free -b|awk '/^Mem:/{print $2}')
    mem_used=$(LANG=C free -b|awk '/^Mem:/{print $3}')
    swap_total=$(LANG=C free -b|awk '/^Swap:/{print $2}')
    swap_used=$(LANG=C free -b|awk '/^Swap:/{print $3}')


    memperc=$(echo "$mem_used" "$mem_total" |  awk '{ div = 100 * ($1 / $2)} { printf "%.0f ", div }' | tr -d ' ' )
    swapperc=$(echo "$swap_used" "$swap_total" |  awk '{
    if ( $1 == 0 || $2 == 0 ) {
        print "%"
    } else {
    div = 100 * ($1 / $2); 
    printf "%.0f ", div
}
}' | tr -d ' ' )


echo "memperc|string|$memperc"
if [ "$swapperc" = "%" ];then
    echo "swapstate|bool|false"
else
    echo "swapperc|string|$swapperc"
    echo "swapstate|bool|true"
fi
echo ""
sleep "$timer"

done