gpt4 book ai didi

linux - 如何在 bash 中发送有关磁盘空间的邮件警报

转载 作者:太空宇宙 更新时间:2023-11-04 04:32:47 24 4
gpt4 key购买 nike

我能够在Linux中发送简单测试的邮件

echo "body" | mail -s "test" xxx@yahoo.com

但是下面的代码不起作用

#!/bin/bash
VAR1=$(df / | grep / | awk '{ print $5}' | sed 's/%//g')
VAR2=$(df /dev/sda1 | grep /dev/sda1 | awk '{ print $5}' | sed 's/%//g')
VAR3=$(df /dev/mapper/centos-var | grep /dev/mapper/centos-var | awk '{ print $5}' | sed 's/%//g')
THRESHOLD=50
TODAY=$(date)
if [ "$VAR1" -gt "$THRESHOLD" ] ; then
mail -s 'Disk Space Alert' rupendra@3ess.in << EOF
Date of $TODAY
Your system partition remaining free space is critically low.
/ partition used is $VAR1%
/ usr partition used is $VAR2%
/ var partition used is $VAR3%

最佳答案

您收到什么错误?

以下一个对我有用,

#!/bin/bash

set -x

VAR1=$(df / | grep / | awk '{ print $5}' | sed 's/%//g')
VAR2=$(df /dev/sda1 | grep /dev/sda1 | awk '{ print $5}' | sed 's/%//g')
VAR3=$(df /dev/mapper/centos-var | grep /dev/mapper/centos-var | awk '{ print $5}' | sed 's/%//g')
THRESHOLD=50
TODAY=$(date)

echo "VAR1=$VAR1, THRESHOLD=$THRESHOLD"

if [ "$VAR1" -gt "$THRESHOLD" ] ; then
mail -s 'Disk Space Alert' abcd@xyz.com << EOF
Date of $TODAY
Your system partition remaining free space is critically low.
/ partition used is $VAR1%
/ usr partition used is $VAR2%
/ var partition used is $VAR3%

EOF

fi

关于linux - 如何在 bash 中发送有关磁盘空间的邮件警报,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49651047/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com