#!/usr/bin/bash
MYHOST="https://www.testwebsite.com"
#Check if Website is up or down
if wget -S $MYHOST 2>&1 | grep -w "200|301" > /dev/null
then
echo "Website is up"
else
#Website is down"
Send mail / mailx to send email
脚本可以发送电子邮件警报,如果网站是关闭,但它会发送重复的电子邮件,直到它是起来。
如何:
- 发送电子邮件警报,如果网站关闭,但警报应该只发送一次。
- 如果是up,邮件应该作为up发送。
网站上下一封邮件
在我看来,我应该将整个if语句包装在while中,并创建一个变量来指示邮件是否被发送
#!/usr/bin/bash
MYHOST="https://www.testwebsite.com" # website
sent=false # sent?
while true
do
get=$(wget -S $MYHOST 2>&1 | grep -w "200|301")
if [ "$get" != "" ] # wget to the website
then
# website is up
echo "Do Something"
else
# website is down
if ! $sent # if the email hasn't been sent yet
then
mailx ...
sent=true
fi
fi
done