检查远程 Linux 服务器是否正在运行


Check if remote linux server is running or not?

我们有10个EC2实例(Linux CentOs)。在给定的时间点,某些实例可能会运行,而某些实例可能会关闭(我们不在任何服务器上运行HTTP服务)

脚本(linux 或 php 或任何)是否有可能从我们持续运行的另一个 linux 服务器检查现在有多少台服务器(共 10 台)启动并运行?

请建议

对于每个实例运行

ping -c3 <your machine address>
ret = $?                              // Get last error or success
if [ $ret -eq 0 ]; then               // If success meas instance is running
    //Increment counter or do whatever you want
fi

我还没有测试过