预期脚本:首先 ping 存储在 hosts.txt 文件中的 IP,如果收到 ping 响应,则运行脚本

预期脚本:首先 ping 存储在 hosts.txt 文件中的 IP,如果收到 ping 响应,则运行脚本

对于下面的代码,我想通过 ping 检查 IP 是否可用,如果可用,则运行下面的代码,从 hosts.txt 检查下一个 IP

编辑 2:仅供参考,我将从 Windows 机器运行脚本

编辑 3:我设法编写了一行,现在此脚本正在 ping hosts.txt 文件中提到的所有 IP,但如果任何 IP 发生故障,则失败。需要的内容:我希望脚本在任何 IP 发生故障时转到下一个 IP。

#!/usr/bin/expect -f

#This Script will provide critical info which are required during troubleshooting

#Setting up Variables
set timeout 15                                                                                                                                 
set fid [open ./hosts.txt r]
set contents [read -nonewline $fid]
close $fid

#Grabbing Password to be used in script further
stty -echo
send_user -- "Enter the Password: "
expect_user -re "(.*)\n"
send_user "\n"
stty echo
set pass $expect_out(1,string)
foreach host [split $contents "\n"] {

    set timeout 5
    spawn ping $host
    expect  {
    "Reply" {puts "$host Is Up"}
    "Request" {puts "$host Is Down"}
        }

相关内容