Skip to content

Commit

Permalink
增加查看主机cpu,内存,磁盘信息脚本
Browse files Browse the repository at this point in the history
  • Loading branch information
elunez committed May 18, 2023
1 parent 4099615 commit eb70816
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions other_script/hostinfo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ cpu_frequency=$(grep 'cpu MHz' /proc/cpuinfo | awk -F ': ' '{print $2}' | head -

# 获取内存信息(以MB为单位)
mem_total=$(free -m | awk '/^Mem:/ {print $2}')
mem_used=$(free -m | awk '/^Mem:/ {print $3}')
mem_free=$(free -m | awk '/^Mem:/ {print $4}')
mem_used=$(free -m | awk '/^Mem:/ {print $6 - $3}')
mem_free=$((mem_total - mem_used))

# 获取硬盘信息
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//')

# 输出结果
echo "--------系统信息---------"
echo -e "CPU数量:$cpu_count | CPU频率:$cpu_frequency MHz"
echo "---------------系统信息----------------"
echo -e "CPU核心:$cpu_count 核心 | CPU频率:$cpu_frequency MHz"
echo -e "CPU型号:$cpu_model"
echo "------------------------"
echo "--------------------------------------"
echo -e "内存大小:$mem_total MB | 已使用:$mem_used MB | 未使用:$mem_free MB"
echo "------------------------"
echo "--------------------------------------"
echo -e "磁盘大小:$disk_total G | 已使用:$disk_used G | 未使用:$disk_free G"
echo "------------------------"
echo "--------------------------------------"

0 comments on commit eb70816

Please sign in to comment.