如何使用Linux检查网站是否向上/向下检查
#!/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。
网站上及以上的一封电子邮件。
#!/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
Script can send an email alert if website is down but it sends repeated emails until it is up.
How to:
- Send an email alert if website is down but alert should be sent only once.
- If it is up, email should be sent as up.
One email for website down and up.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为,我将在一段时间内包装整个IF语句,并创建一个变量以指示是否发送了邮件
In my opinion, I would wrap the whole if statement in a while and create a variable to indicate if the mail is sent