0

我有一个 mailx 语句作为 shell scipt 的一部分。它是条件声明的一部分,如果系统出现故障,它将每分钟发送一封电子邮件。

有没有办法让 mailx 检查邮件是否在最后一小时内发送,并且仅在结果为假时发送?

tail -1 "/location/of/file.txt" | mail -s "Warning" test@testing.com;
4

1 回答 1

2

使用文件来标记您发送的时间。例如

dowork() {
    tail -1 "/location/of/file.txt" | mail -s "Warning" test@testing.com;
    touch ./checked.txt
}
if [[ -f ./checked.txt ]] ; then
    if [[ $(expr $(date '+%s') - $(stat -c '%Y' ./checked.txt )) -gt 3600 ]]; then
            dowork
    fi
else
    dowork
fi
于 2012-07-04T23:31:19.340 回答