-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathsystem_info.sh
executable file
·124 lines (115 loc) · 3.06 KB
/
system_info.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/usr/bin/env bash
# Script Name: system_info.sh
# Description: This script displays detailed information about the system.
# Usage: ./system_info.sh [options]
# Example: ./system_info.sh --memory --disk
# Enforce strict mode
set -euo pipefail
# Constants
readonly SCRIPT_NAME=$(basename "${0}")
print_usage() {
echo "Usage: ${SCRIPT_NAME} [OPTIONS]"
echo "Displays detailed information about the system."
echo
echo "Options:"
echo " -h, --help Display this help message and exit."
echo " --memory Display memory usage."
echo " --disk Display disk usage."
echo " --cpu Display CPU information."
echo " --network Display network interfaces."
echo " --processes Display running processes."
echo " --os Display operating system details."
echo " --kernel Display kernel version."
echo " --filesystems Display mounted filesystems."
echo " --load Display system load."
echo " --all Display all available information."
}
print_help() {
print_usage
}
# Default options
show_memory=false
show_disk=false
show_cpu=false
show_network=false
show_processes=false
show_os=false
show_kernel=false
show_filesystems=false
show_load=false
show_all=false
# Parse command-line options
while [[ $# -gt 0 ]]; do
case "$1" in
-h|--help)
print_help
exit 0
;;
--memory)
show_memory=true
;;
--disk)
show_disk=true
;;
--cpu)
show_cpu=true
;;
--network)
show_network=true
;;
--processes)
show_processes=true
;;
--os)
show_os=true
;;
--kernel)
show_kernel=true
;;
--filesystems)
show_filesystems=true
;;
--load)
show_load=true
;;
--all)
show_all=true
;;
*)
echo "Error: Unknown option: $1"
print_usage
exit 1
;;
esac
shift
done
main() {
if $show_memory || $show_all; then
echo -e "Memory Usage: \n$(free -h)\n"
fi
if $show_disk || $show_all; then
echo -e "Disk Usage (Top 10): \n$(df -Ph | sort -k 5 -h -r | head)\n"
fi
if $show_cpu || $show_all; then
echo -e "CPU Information: \n$(lscpu)\n"
fi
if $show_network || $show_all; then
echo -e "Network Interfaces: \n$(ip -br address)\n"
fi
if $show_processes || $show_all; then
echo -e "Running Processes: \n$(ps aux)\n"
fi
if $show_os || $show_all; then
echo -e "Operating System: \n$(lsb_release -a)\n"
fi
if $show_kernel || $show_all; then
echo -e "Kernel Version: \n$(uname -r)\n"
fi
if $show_filesystems || $show_all; then
echo -e "Mounted Filesystems: \n$(mount | grep '^/dev')\n"
fi
if $show_load || $show_all; then
echo -e "System Load: \n$(uptime)\n"
fi
}
main "$@"