-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdisk_check.sh
More file actions
30 lines (26 loc) · 984 Bytes
/
disk_check.sh
File metadata and controls
30 lines (26 loc) · 984 Bytes
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
#!/bin/bash
# Define the check_disk function
# Functions allow you to group code blocks and call them by name later.
check_disk(){
echo "Disk Usage"
# df -h /: Shows disk space in human-readable format for the root directory.
# awk 'NR==2': Processes the second line (skipping the header).
# {print ...}: Formats and prints specific columns (2, 3, and 4).
df -h / | awk 'NR==2 {print " Size: " $2, "Used: " $3, "Available: " $4}'
}
# Define the check_memory function
check_memory(){
echo "Free Memory"
# free -h: Shows memory usage in human-readable format (G/M).
# awk 'NR==2': Focuses on the "Mem:" line.
# $4 represents the "Free" column in the 'free' command output.
free -h | awk 'NR==2 {print " " $4 " free"}'
}
# Main function: This acts as the entry point of your script.
# It controls the execution flow and makes the script cleaner.
main(){
check_disk
check_memory
}
# Calling the main function to trigger the logic
main