事实上,我有 2 个路由器都配置了 DDNS 帐户。
我想设置一个脚本,以便在路由器上的互联网服务出现故障时发送电子邮件通知。
例如,
ping router1.ddns.net ,得到回复,网络正常。 ping router2.ddns.net,没有回复,网络不正常,发送电子邮件通知。
请注意,我确实有防火墙,但它无法在互联网服务中断时发送通知。
最佳答案
你可以使用mailx
(我的偏好,因为它是最简单的)
echo "this is the body of the email" | mailx -vvv -s "test mail" -r "From" -S smtp="your-smtp" someone@address
gmail配置示例
vi ~/.mailrc
account gmail {
set smtp-use-starttls
set ssl-verify=ignore
set smtp-auth=login
set smtp=smtp://smtp.gmail.com:587
set from="<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="335d5c4156435f4a734a5c4641575c5e525a5d1d505c5e" rel="noreferrer noopener nofollow">[email protected]</a>(Your Real Name)"
set <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="37445a43471a5642435f1a424452450a59584552475b4e774e58424553585a565e591954585a" rel="noreferrer noopener nofollow">[email protected]</a>
set smtp-auth-password=your_less_secure_apps_password
set ssl-verify=ignore
}
然后
echo -e "Mail body text" | mailx -A gmail -s "Mail subject" your@email
关于bash - 没有互联网 - 电子邮件通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63881041/