首页 > 解决方案 > 如何在一个脚本中为磁盘和内存使用编写 shell 脚本并创建电子邮件警报

问题描述

我正在尝试一起编写一个用于磁盘使用和内存使用的 shell 脚本。但是我不能一起写磁盘和内存,但我可以单独写,那些脚本是成功的[用于磁盘和内存使用的 shell 脚本1

#!/bin/bash

diskusage=$(df -Ph | grep '/webm9' | awk {'print $5'})
memusage=$(free | grep Mem | awk {'print $3/$2 * 100.0}')

a=80%
b=50%

if [ "diskusage" >  a ]; then
    echo "The Mount Point "/DB" on $(hostname) has used $diskusage at $(date)" | mail -s "Disk space alert on $(hostname): $diskusage used" xy@gmail.com
if [ "memusage" >  b]; then
    echo "The Mount Point "/DB" on $(hostname) has used $memusage at $(date)" | mail -s "memory space alert on $(hostname): $memusage used" xy@gmail.com
fi

任何人都可以请帮助与一个脚本一起编写。

标签: linuxbashshellmemorydisk

解决方案


推荐阅读