bash - 用于检查服务器是否可达的 Shell 脚本?

标签 bash shell solaris-10

我有 5 个 Solaris 服务器分布在不同的位置。 有时,由于各种原因(网络问题或服务器本身突然宕机),无法从我所在的位置访问其中一些服务器。

所以我想写一个 Bash shell 脚本来检查它们是否可达。我尝试过的是:

ssh ipaddress "uname -a"

设置了无密码验证。如果我没有得到任何输出,我将生成一封邮件。

  1. 有没有其他方法可以检查服务器的可达性?
  2. 哪种方法最好?
  3. 我的尝试是否正确?

最佳答案

您可以做的最简单的检查可能是使用 netcat 检查开放端口。

要检查 SSH(端口 22)的可达性,您可以这样做

if nc -z $server 22 2>/dev/null; then
    echo "$server ✓"
else
    echo "$server ✗"
fi

来自手册页:

-z   Specifies that nc should just scan for listening daemons, without sending any data to them.

关于bash - 用于检查服务器是否可达的 Shell 脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8937663/

相关文章:

linux - 在单实例模式下使用 xinetd 运行 shell 脚本

python - Django 从 celery 的 subprocess.Popen 获得干净的返回

python -/bin/sh : line 62: to: command not found

solaris-10 - 如何判断我使用的是 x64 位还是 32 位 Solaris 10

c - 警告 : improper pointer/integer combination: op "="

java - 具有多个字符串参数的 Bash 脚本

linux - 参数未传递给 shell 脚本 copyfile.sh : 1: copyfile. sh: [d: 未找到

linux - 只复制 SCP 不存在的文件

linux - 如何在 Linux 中保护 .bash_history 文件

谁能告诉我如何在sunsolaris系统中运行udp客户端服务器程序?