问题描述
事实上,我有2个路由器都配置了DDNS帐户。
我想设置一个脚本,以便在路由器上的Internet服务中断的情况下可以发送电子邮件通知。
例如,
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="noreply@yourdomain.com(Your Real Name)"
set smtp-auth-user=noreply@yourdomain.com
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