bash - 没有互联网 - 电子邮件通知

标签 bash email ping

事实上,我有 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/

相关文章:

Linux:根据匹配从文本文件中提取指定行数

c++ - 从 Linux 中的 C/C++ 程序发送电子邮件

PHP 电子邮件 header - 传送选项

linux - 使用 rc.local 回显密码命令

linux - 未找到 Bash 脚本,尽管它在 $PATH 中

linux - 为什么我必须在容器中使用 bash -l -c?

python - 如何在Python中对事件监听器和函数应用多处理?

apple-push-notifications - Ping 到 APNS 不返回

c# - Ping 或以其他方式通过 C# 中的 MAC 判断设备是否在网络上

macos - 对安全主机 URL 执行 Ping