用于监控 ISDN 连接的 Bash 脚本

发布于 2024-09-04 06:50:48 字数 549 浏览 1 评论 0原文

在 Ubuntu 10.04 服务器上,我想使用 bash 脚本执行以下操作:

创建一个监视 ISDN 连接的服务,如果停机时间超过 60 秒,则强制重新连接。 我当前的解决方案如下所示:

#!/usr/bin/bash
LOGFILE=/home/msw/router/ping-stats.txt
TIME="`date +%C%y%m%d%H%M`"
/sbin/ping -c 1 google.com > /dev/null 2>&1
if [ "$?" == "0" ]
then
        STATUS=1
else
        STATUS=0
fi
echo "$TIME $STATUS" >> $LOGFILE

由于 ISDN 连接上的带宽非常宝贵,因此我想避免 ping 并将其替换为仅检查网络设备状态的命令。是否可以从中推断连接是否“正常”?

我还想将该解决方案实现为一项服务,持续检查连接性,而不是使用 cronjob 定期检查。

如果有人能将我推向正确的方向,我将非常感激。

谢谢

On a Ubuntu 10.04 Server I would like to do the following with a bash script:

Create a service that monitors the ISDN connection and if downtime exceeds 60 seconds forces reconnect.
My current solution looks something like this:

#!/usr/bin/bash
LOGFILE=/home/msw/router/ping-stats.txt
TIME="`date +%C%y%m%d%H%M`"
/sbin/ping -c 1 google.com > /dev/null 2>&1
if [ "$?" == "0" ]
then
        STATUS=1
else
        STATUS=0
fi
echo "$TIME $STATUS" >> $LOGFILE

Since bandwidth is precious on an ISDN connection, I would like to avoid the ping and replace it with a command that simply checks for the status of the network device. Is it possible to infer from that if the connection is "up"?

I would also like to implement the solution as a service that checks connectivity continually instead of checking periodically with a cronjob.

I would really appreciate it if somebody could push me in the right direction.

Thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

寄人书 2024-09-11 06:50:48

对于快速而肮脏的工具,有nm-tooldbus-send 可以更精确一些,但需要了解 D-Bus 如何与 NetworkManager 配合使用。如果您想要持久的东西,那么您需要学习如何与 D-Bus 交互,但这可能需要使用一些较低级别的东西,例如 Python。

For quick-and-dirty there's nm-tool. dbus-send can be a bit more precise, but needs knowledge of how D-Bus works with NetworkManager. If you want something persistent then you'll need to learn how to interact with D-Bus, but that may require using something a bit lower-level such as Python.

挽手叙旧 2024-09-11 06:50:48

您的 ISDN 是通过内部适配器还是通过以太网连接提供的?如果您有外部“调制解调器”,则需要使用 SNMP 或其专有工具进行查询。

顺便说一句,您可以这样进行测试:此外

if /sbin/ping -c 1 google.com > /dev/null 2>&1
then
    ...

,单个 ping 的字节数非常少。如果你每分钟只做几次,你可能永远不会注意到它。

Is your ISDN provided by an internal adapter or via an Ethernet connection? If you have an external "modem" you'd need to query that using SNMP or its proprietary facility.

You can do your test this way, by the way:

if /sbin/ping -c 1 google.com > /dev/null 2>&1
then
    ...

Also, a single ping is a very small number of bytes. If you're only doing it a few times a minute you may never notice it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文