xfce4에서 generic monitor활용 (막대그래프)
2020.02.12 09:32
0 #!/bin/bash
1 res=$(free -h)
2 total=$(printf "$res" | grep Mem | awk -F ' ' '{print $2}')
3 used=$(printf "$res" | grep Mem | awk -F ' ' '{print $3}')
4
5 t="${total::-1}"
6 u="${used::-1}"
7 if [[ "${used: -1}" == "M" ]]; then
8 r=$(echo "$u / $t * 0.1" | bc -l)
9 elif [[ "${used: -1}" == "G" ]]; then
10 r=$(echo "$u / $t * 100" | bc -l)
11 fi
12
13 res=$(printf "%.0f\n" $r)
14 color="#ffffff"
15
16 # image size
17 width=85
18 height=24
19 bar_length=$(echo "$r * $width / 100" | bc -l)
20 r=$(printf "%.*f\n" 1 $r)
21 echo "<txt><span foreground=\"$color\">$r%</span></txt>"
22
23 convert -size "$width"x"$height" canvas:white -stroke "orange" \
24 -draw "fill black rectangle 0,0,$(( width - 1 )),$(( height - 1))" \
25 -draw "fill cyan rectangle 0,0,$bar_length,$height" \
26 $HOME/.icons/mem_bar.png
27
28 echo "<click>xfce4-taskmanager</click>"
29 echo "<tool>Used: $used / $total</tool>"
30 echo "<img>$HOME/.icons/mem_bar.png</img>"
