-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ram_usage_motd.sh
83 lines (57 loc) · 1.42 KB
/
Ram_usage_motd.sh
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
green () {
echo -e "\u001b[32m$1\u001b[0m"
}
yellow () {
echo -e "\u001b[33m$1\u001b[0m"
}
red () {
echo -e "\u001b[31m$1\u001b[0m"
}
Ram_usage () {
total=$(( $(cat /proc/meminfo | grep MemTotal: | sed 's|.* \([0-9]*\) kB|\1|' ) + $(cat /proc/meminfo | grep SwapTotal: | sed 's|.* \([0-9]*\) kB|\1|' ) ))
free=$(( $(cat /proc/meminfo | grep MemFree: | sed 's|.* \([0-9]*\) kB|\1|' ) + $(cat /proc/meminfo| grep SwapFree: | sed 's|.* \([0-9].*\) kB|\1|') ))
cache_buffer=$(( $(cat /proc/meminfo| grep ^Cached: | sed 's|.* \([0-9].*\) kB|\1|') + $(cat /proc/meminfo| grep Buffers: | sed 's|.* \([0-9].*\) kB|\1|') + $(cat /proc/meminfo | grep SReclaimable: | sed 's|.* \([0-9].*\) kB|\1|' ) ))
use=$(( ( $total - ( $free + $cache_buffer ) ) /1000 ))
total=$(( $total / 1000 ))
suff_t="MB"
suff_u="MB"
percent=$(( ( ( ( $use * 1000 ) / total ) +5 ) / 10 ))
if [ "${#total}" -gt 3 ]
then
total=$(( $total / 1000 ))
suff_t="GB"
fi
if [ "${#use}" -gt 3 ]
then
free=$(( $use / 1000 ))
suff_u="GB"
fi
i=0
bar=""
while [ $(( $percent /10 )) -gt $i ]
do
bar="$bar■"
i=$(($i+1))
done
if [ $percent -gt 66 ]
then
bar=$(red $bar)
else
if [ $percent -gt 33 ]
then
bar=$(yellow $bar)
else
bar=$(green $bar)
fi
fi
i=0
while [ $(( 10 - ( $percent / 10 ) )) -gt $i ]
do
bar="$bar "
i=$(($i+1))
done
echo RAM use: $percent% \["$bar"\] $use $suff_u/$total $suff_t
}
white=$(echo -e "\u001b[0m")
echo $white
Ram_usage