期待ping测试的脚本

问题描述 投票:1回答:1

您好,我想制作一个脚本来测试ping并将输出放入文件中。感谢您的所有帮助。

#!/usr/bin/expect -f

    set IPaddress [lindex $argv 0]
    set fildes [open "ip.txt" r]
    set output [open "out.txt"]

while {[gets $fildes ip ] != -1} {

    set timeout 5
    spawn ping -c 3 $ip
    expect  {
        " 0%"   {puts "$ip Is Up"}
        " 100%" {puts "$ip Is Down"}
        }
}

我想把看跌期权“ $ ip Is Up”和$ ip Down写入文件out.txt然后我要计算有多少IP启用和有多少IP停用。喜欢:

30 Ips Is up
20 Ips Is down

我也想要out.txt中的计数。

bash shell scripting expect
1个回答
0
投票

现在工作,我只需要添加“ w”,这是我的代码更新:

!/ usr / bin / expect -f

set IPaddress [lindex $argv 0]
set fildes [open "ip.txt" r]
set output [open "out.txt" w]

while {[gets $ fildes ip]!= -1} {

set timeout 5
spawn ping -c 3 $ip
expect  {
    " 0%"   {puts $output "$ip Is Up"}
    " 100%" {puts $output "$ip Is Down"}
    }

}

© www.soinside.com 2019 - 2024. All rights reserved.