系统巡检脚本

 

 

#!/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"

 

posted @ 2024-09-30 16:06  太阳的阳ฅ  阅读(11)  评论(0编辑  收藏  举报