-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.sh
More file actions
executable file
·90 lines (72 loc) · 2.68 KB
/
script.sh
File metadata and controls
executable file
·90 lines (72 loc) · 2.68 KB
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
83
84
85
86
87
88
89
90
#!/bin/bash
# Copyright (C) 2025 İbrahim Hakkı Ergin <ibrahimh.ergin@gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.s
red="\e[31m"
green="\e[32m"
yellow="\e[33m"
bold="\e[1m"
italic="\e[2m"
reset="\e[0m"
echo -e "${bold}System Usage Analysis${reset} \n"
# Memory analysis
echo -e "${italic}Memory: ${reset}"
total_mem_gib=$(LANG=C free -h | grep Mem: | awk '{print $2}')
used_mem_gib=$(LANG=C free -h | grep Mem: | awk '{print $3}')
total_mem=$(LANG=C free | grep Mem: | awk '{print $2}')
used_mem=$(LANG=C free | grep Mem: | awk '{print $3}')
mem_perc=$(LANG=C free -b | awk '/Mem:/ {printf "%.0f", ($3/$2)*100}')
if [ $mem_perc -ge 50 ]; then
echo -e "${red}$total_mem_gib / $used_mem_gib ${reset}"
else
echo -e "${green}$total_mem_gib / $used_mem_gib ${reset}"
fi
# Swap analysis
echo -e "${italic}Swap: ${reset}"
total_swap_gib=$(LANG=C free -h | grep Swap: | awk '{print $2}')
used_swap_gib=$(LANG=C free -h | grep Swap: | awk '{print $3}')
total_swap=$(LANG=C free | grep Swap: | awk '{print $2}')
used_swap=$(LANG=C free | grep Swap: | awk '{print $3}')
swap_perc=$(LANG=C free -b | awk '/Swap:/ {printf "%.0f", ($3/$2)*100}')
if [ "$total_swap" -gt 0 ]; then
swap_perc=$(LANG=C free -b | awk '/Swap:/ {printf "%.0f", ($3/$2)*100}')
else
swap_perc=0
fi
if [ "$swap_perc" -ge 1 ]; then
echo -e "${red}$total_swap_gib / $used_swap_gib ${reset}"
else
echo -e "${green}$total_swap_gib / $used_swap_gib ${reset}"
fi
# CPU analysis
echo -e "${italic}CPU: ${reset}"
cpu_usage=$(top -bn1 | awk '/Cpu/ { print $2}')
cpu_usage_int=$(echo "$cpu_usage" | cut -d',' -f1)
if [ $cpu_usage_int -le 10 ]; then
echo -e "${green}%$cpu_usage${reset}"
elif [ $cpu_usage_int -le 50 ]; then
echo -e "${yellow}%$cpu_usage${reset}"
else
echo -e "${red}%$cpu_usage${reset}"
fi
# Disk analysis
echo -e "${italic}Disk: ${reset}"
root_disk_usg=$(df -h | awk '$NF == "/" {print $5}' | cut -d'%' -f1)
if [ $root_disk_usg -le 20 ]; then
echo -e "${green}%$root_disk_usg${reset}"
elif [ $root_disk_usg -le 60 ]; then
echo -e "${yellow}%$root_disk_usg${reset}"
else
echo -e "${red}%$root_disk_usg${reset}"
fi