-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
34 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,39 @@ | ||
#!/bin/bash | ||
|
||
# 获取CPU信息 | ||
cpu_count=$(grep -c '^processor' /proc/cpuinfo) | ||
cpu_model=$(grep 'model name' /proc/cpuinfo | awk -F ': ' '{print $2}' | head -1) | ||
cpu_frequency=$(grep 'cpu MHz' /proc/cpuinfo | awk -F ': ' '{print $2}' | head -1) | ||
while true; do | ||
# 获取CPU信息 | ||
cpu_count=$(grep -c '^processor' /proc/cpuinfo) | ||
cpu_model=$(grep 'model name' /proc/cpuinfo | awk -F ': ' '{print $2}' | head -1) | ||
cpu_frequency=$(grep 'cpu MHz' /proc/cpuinfo | awk -F ': ' '{print $2}' | head -1) | ||
|
||
# 获取内存信息(以MB为单位) | ||
mem_total=$(free -m | awk '/^Mem:/ {print $2}') | ||
mem_used=$(free -m | awk '/^Mem:/ {print $6 - $3}') | ||
mem_free=$((mem_total - mem_used)) | ||
# 获取CPU负载 | ||
cpu_usage=$(top -bn1 | grep "Cpu(s)" | awk '{print $2 + $4}') | ||
cpu_idle=$(awk -v usage="$cpu_usage" 'BEGIN {print 100 - usage}') | ||
load_average=$(cat /proc/loadavg | awk '{print $1, $2, $3}') | ||
|
||
# 获取硬盘信息 | ||
disk_total=$(df -h --output=size / | awk 'NR==2' | sed 's/G//') | ||
disk_used=$(df -h --output=used / | awk 'NR==2' | sed 's/G//') | ||
disk_free=$(df -h --output=avail / | awk 'NR==2' | sed 's/G//') | ||
# 获取内存信息 | ||
mem_total=$(free -m | awk '/^Mem:/ {print $2}') | ||
mem_used=$(free -m | awk '/^Mem:/ {print $6 - $3}') | ||
mem_free=$((mem_total - mem_used)) | ||
|
||
# 输出结果 | ||
echo "---------------系统信息----------------" | ||
echo -e "CPU核心:$cpu_count 核心 | CPU频率:$cpu_frequency MHz" | ||
echo -e "CPU型号:$cpu_model" | ||
echo "--------------------------------------" | ||
echo -e "内存大小:$mem_total MB | 已使用:$mem_used MB | 未使用:$mem_free MB" | ||
echo "--------------------------------------" | ||
echo -e "磁盘大小:$disk_total G | 已使用:$disk_used G | 未使用:$disk_free G" | ||
echo "--------------------------------------" | ||
# 获取硬盘信息 | ||
disk_total=$(df -h --output=size / | awk 'NR==2' | sed 's/G//' | tr -d '[:space:]') | ||
disk_used=$(df -h --output=used / | awk 'NR==2' | sed 's/G//' | tr -d '[:space:]') | ||
disk_free=$(df -h --output=avail / | awk 'NR==2' | sed 's/G//' | tr -d '[:space:]') | ||
|
||
# 清空屏幕 | ||
clear | ||
|
||
# 输出结果 | ||
echo "--------------------------CPU信息----------------------------" | ||
echo -e "CPU核心: $cpu_count 核心 | CPU型号: $cpu_model $cpu_frequency MHz" | ||
echo "--------------------------CPU负载----------------------------" | ||
echo -e "CPU使用率: $cpu_usage % | CPU空闲率: $cpu_idle % | 负载参数: $load_average" | ||
echo "--------------------------内存信息---------------------------" | ||
echo -e "内存大小: $mem_total MB | 已使用: $mem_used MB | 未使用: $mem_free MB" | ||
echo "---------------------------磁盘信息--------------------------" | ||
echo -e "磁盘大小: $disk_total G | 已使用: $disk_used G | 未使用: $disk_free G" | ||
echo "-------------------------------------------------------------" | ||
# 暂停800毫秒 | ||
sleep 0.8 | ||
done |