Linux简单使用的服务器日常巡检脚本

#! /bin/bash
time=`date "+%Y-%m-%d %H:%M:%S"`
hostname=`hostname`
total=`free -m | awk 'NR==2{print $2}'`
used=`free -m | awk 'NR==2{print $3}'`
cpu_idle=`top -b -n 1 | grep Cpu | awk '{print $8}' | cut -f 1 -d "."`
cpu_use=`expr 100 - $cpu_idle`
total_disk=$(df -h | awk '/\/$/ {print $2}')
used_disk=$(df -h | awk '/\/$/ {print $3}')

echo "========================= CPU | Memory | Disk ======================"

echo $time $hostname
echo "CPU 使用率: ${cpu_use}% CPU空闲: ${cpu_idle}%"
total_free=$(awk "BEGIN { printf \"%.2f\",$total / 1024}")
echo "总内存:${total_free}G"
used_free=$(awk "BEGIN { printf \"%.2f\",$used / 1024}")
echo "已用内存:${used_free}G"
disk_usage=$(df -h | awk '/\/$/ {print $5}')
echo  "磁盘使用率: $disk_usage"
men_usage=$((used * 100 / total))
echo "内存使用率: $men_usage%"

你可能感兴趣的:(linux,服务器,linux,运维)