设计一个Shell脚本,可以检测服务器上的磁盘空间,并在空间不足时发送报警邮件。

设计一个Shell脚本

#!/bin/bash

# 获取磁盘空间
disk_space=$(df -h | awk 'NR==2{print $5}')

# 设置阈值
threshold=90

# 比较磁盘空间与阈值
if [ ${disk_space%?} -ge $threshold ]
then
    # 发送报警邮件
    mail -s '磁盘空间不足' admin@example.com <<< 'Server磁盘空间已超过90%'
fi