Generate a Complete Linux Server Health Report with a Single Command
This article introduces a lightweight Bash script that, with one curl command, automatically gathers CPU, memory, disk, and network information from a Linux server and outputs a formatted, color‑coded report in seconds, dramatically simplifying routine ops tasks.
Today I share a hidden gem for Linux operations: a one‑line solution that instantly provides CPU, memory, disk, and IP details without manually running multiple commands like cat /proc/cpuinfo , free -h , df -h , or ip addr .
Now a single command can generate a formatted, color‑coded server health report covering all key information.
Here is the "Health Report" you need
Run the following command and obtain a structured server configuration list in about three seconds:
curl -s 'https://download.xlsys.cn/tools/Shell/system_info.sh' | bashIf you need to check a remote server, execute it via SSH:
# Remote server execution example
ssh user@host "curl -s https://download.xlsys.cn/tools/Shell/system_info.sh | bash"Previously, assembling a configuration list required half an hour of manual commands; now the script produces a professional report in ten seconds, ready to send to customers.
Original Script
#!/bin/bash
# Script name: system_info.sh
# Version: 1.0
# Date: 2024/12/01
# Author: Jack.liu
# Email: [email protected]
# URL: www.xlsys.cn
GREEN='\033[0;32m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
print_title() {
echo -e "${GREEN}================== $1 信息 ==================${NC}"
}
# Physical CPU count
print_title "物理CPU个数"
physical_cpu_count=$(cat /proc/cpuinfo | grep "physical id" | sort | uniq | wc -l)
echo "物理CPU个数: $physical_cpu_count"
# Logical CPU count
print_title "逻辑CPU个数"
logical_cpu_count=$(cat /proc/cpuinfo | grep "processor" | wc -l)
echo "逻辑CPU个数: $logical_cpu_count"
# CPU cores
print_title "CPU核心数"
cpu_cores=$(cat /proc/cpuinfo | grep "cpu cores" | uniq)
echo "$cpu_cores"
# CPU frequency
print_title "CPU主频"
cpu_mhz=$(cat /proc/cpuinfo | grep "MHz" | uniq)
echo "$cpu_mhz"
# Memory information
print_title "内存"
total_mem_kb=$(cat /proc/meminfo | grep MemTotal | awk '{print $2}')
used_mem_kb=$(free -k | awk 'NR==2{print $3}')
free_mem_kb=$(free -k | awk 'NR==2{print $4}')
total_mem_gb=$(awk "BEGIN {printf \"%.2f\", $total_mem_kb / 1024 / 1024}")
used_mem_gb=$(awk "BEGIN {printf \"%.2f\", $used_mem_kb / 1024 / 1024}")
free_mem_gb=$(awk "BEGIN {printf \"%.2f\", $free_mem_kb / 1024 / 1024}")
echo "总内存: $total_mem_gb GB"
echo "已用内存: $used_mem_gb GB"
echo "空闲内存: $free_mem_gb GB"
# Disk information
print_title "硬盘"
lsblk -b -o NAME,SIZE | awk 'NR>1 && $2 > 0 {size_gb = $2 / (1024^3); printf "%-10s : %.2f GB
", $1, size_gb}'
# IP address information
print_title "IP地址"
ip -4 addr show | grep -oP '(?<=inet\s)\d+(\.\d+){3}' | while read ip; do
interface=$(ip -4 addr show | grep "$ip" -B1 | grep -oP '(?<=\d:\s)\S+')
printf "%-15s : %s
" "$interface" "$ip"
doneIn Summary
This script contains no complex logic or flashy code, yet it solves a common ops pain point—fragmented information—by consolidating data from five commands into a clear report, freeing you from repetitive work.
One‑click command (copy and save)
curl -s 'https://download.xlsys.cn/tools/Shell/system_info.sh' | bashView source (audit safely)
curl -s https://download.xlsys.cn/tools/Shell/system_info.shTrue operational efficiency tools should be this simple: type less, solve more.
Xiao Liu Lab
An operations lab passionate about server tinkering 🔬 Sharing automation scripts, high-availability architecture, alert optimization, and incident reviews. Using technology to reduce overtime and experience to avoid major pitfalls. Follow me for easier, more reliable operations!
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
