check_system_info.info
This script provides comprehensive system information, including system uptime, hardware details, temperature readings, systemctl status, memory (RAM and SWAP) usage, disk space and inode usage, and recent reboot/shutdown events. It’s a valuable tool for system administrators and users who need to quickly gather and review essential system metrics on Linux.
ChatGPT has contributed to this document. Therefore, it’s advisable to treat the information here with caution and verify it if necessary.
Let’s break down what this script does in detail. The script is named
check_system_info.sh
, authored by GJS (homelab-alpha), and its purpose is to
check various aspects of system information. It provides details about system
uptime, hardware information, system temperature, systemctl status, RAM/SWAP
usage, disk usage, disk usage inodes, and last reboot/shutdown events.
Here’s a detailed explanation:
Script Metadata
- Filename:
check_system_info.sh
- Author: GJS (homelab-alpha)
- Date: May 18, 2024
- Version: 1.0.1
- Description: This script checks system information. It provides details about system uptime, hardware information, system temperature, systemctl status, RAM/SWAP usage, disk usage, disk usage inodes, and last reboot/shutdown events.
- RAW Script: check_system_info.sh
Script Structure and Functions
Print Section Separators
The script includes a function print_separator
to print a line separator for
clarity.
print_separator() {
echo "────────────────────────────────────────────────────────────────────────────────"
}
Check if a Command Exists
A helper function command_exists
checks if a command is available on the
system.
command_exists() {
command -v "$1" >/dev/null 2>&1
}
Initial Information
Prints the current date, user, and system uptime.
print_separator
echo "$(date) │ $(whoami)@$(hostname --all-ip-addresses) │ $(uptime --pretty)"
print_separator
Checking for Required Commands
Check for Required Commands
It checks if the necessary commands (sensors
, hostnamectl
, df
, last
) are
available and lists any missing commands.
missing_commands=()
if ! command_exists "sensors"; then
missing_commands+=("sensors")
fi
if ! command_exists "hostnamectl"; then
missing_commands+=("hostnamectl")
fi
if ! command_exists "df"; then
missing_commands+=("df")
fi
if ! command_exists "last"; then
missing_commands+=("last")
fi
if [ ${#missing_commands[@]} -eq 0 ]; then
echo "All required software is present."
else
echo "The following software is missing:"
for cmd in "${missing_commands[@]}"; do
echo " - $cmd"
done
echo "You can install missing software manually using your package manager."
fi
Detailed System Information
System Info
Prints system model information and hostname details.
print_separator
echo "System info:"
echo ""
if command_exists "cat"; then
cat /proc/device-tree/model
else
echo "ERROR: 'cat' command not found."
fi
echo ""
if command_exists "hostnamectl"; then
hostnamectl
else
echo "ERROR: 'hostnamectl' command not found."
fi
print_separator
System Temperature
Checks and prints system temperature using the sensors
command.
echo "System temperature:"
echo ""
if command_exists "sensors"; then
sensors
else
echo "ERROR: 'sensors' command not found."
fi
print_separator
Systemctl Status
Displays the status of failed system services.
echo "Systemctl status:"
echo ""
if command_exists "systemctl"; then
systemctl --failed
else
echo "ERROR: 'systemctl' command not found."
fi
print_separator
RAM/SWAP Usage
Shows RAM and SWAP usage using the free
command.
echo "RAM/SWAP usage:"
echo ""
if command_exists "free"; then
free --human
else
echo "ERROR: 'free' command not found."
fi
print_separator
Disk Usage
Provides detailed disk usage information.
echo "Disk usage:"
echo ""
if command_exists "df"; then
df --human-readable --type=ext4 --output=source,size,used,avail,pcent,target
else
echo "ERROR: 'df' command not found."
fi
print_separator
Disk Usage Inodes
Shows inode usage of the disk.
echo "Disk usage inodes:"
echo ""
if command_exists "df"; then
df --human-readable --inodes
else
echo "ERROR: 'df' command not found."
fi
print_separator
Last Reboot/Shutdown Events
Displays the last three system shutdown events.
echo "Last reboot/shutdown:"
echo ""
if command_exists "last"; then
last --system | grep shutdown | head --lines=3
else
echo "ERROR: 'last' command not found."
fi
print_separator
Conclusion
The script is well-organized, providing clear output of the system status and any missing software that may be needed to perform certain checks. It’s handy for quickly diagnosing the state of a Linux system.
Last updated 22 Sep 2024, 12:15 CEST .