简体   繁体   中英

How to check if Mailx used in the past timeframe?

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. eg

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM