#!/bin/bash # 获取CPU使用率 cpu_usage() { echo "CPU Usage:" top -bn1 | grep "Cpu(s)" | awk '{print "User: " $2 "%, System: " $4 "%, Idle: " $8 "%"}' } # 获取内存使用情况 memory_usage() { echo "Memory Usage:" free -h | awk 'NR==2{printf "Total: %s, Used: %s, Free: %s\n", $2, $3, $4}' } # 获取磁盘使用情况 disk_usage() { echo "Disk Usage:" df -h | awk 'NR!=1 {printf "Filesystem: %s, Size: %s, Used: %s, Avail: %s, Use%: %s, Mounted on: %s\n", $1, $2, $3, $4, $5, $6}' } # 打印标题 echo "System Health Check Report" echo "==========================" echo "Date: $(date)" echo "==========================" echo "" # 调用各个函数 cpu_usage echo "" memory_usage echo "" disk_usage echo "" # 脚本结束 echo "System Health Check Completed"
标签:脚本,巡检,系统,System,echo,Usage,awk,usage,Health From: https://www.cnblogs.com/goujinyang/p/18442008