문제

I have a mailx statement as part of a shells scipt. It is part of a condtional statement that will send an email every minute if a system is failing.

Is there a way to have mailx check if a mail was send in the last hour and only send if result is false?

tail -1 "/location/of/file.txt" | mail -s "Warning" test@testing.com;
도움이 되었습니까?

해결책

use a file to mark the time you send. e.g.

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
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top